Skip to content

Commit bbf3c7f

Browse files
JustinStittkees
authored andcommitted
lib/string_helpers: rework overflow-dependent code
When @SiZe is 0, the desired behavior is to allow unlimited bytes to be parsed. Currently, this relies on some intentional arithmetic overflow where --size gives us SIZE_MAX when size is 0. Explicitly spell out the desired behavior without relying on intentional overflow/underflow. Signed-off-by: Justin Stitt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 0336f89 commit bbf3c7f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/string_helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ int string_unescape(char *src, char *dst, size_t size, unsigned int flags)
321321
{
322322
char *out = dst;
323323

324+
if (!size)
325+
size = SIZE_MAX;
326+
324327
while (*src && --size) {
325328
if (src[0] == '\\' && src[1] != '\0' && size > 1) {
326329
src++;

0 commit comments

Comments
 (0)