Skip to content

Commit

Permalink
lib/string_helpers: rework overflow-dependent code
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
JustinStitt authored and kees committed Aug 15, 2024
1 parent 0336f89 commit bbf3c7f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/string_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ int string_unescape(char *src, char *dst, size_t size, unsigned int flags)
{
char *out = dst;

if (!size)
size = SIZE_MAX;

while (*src && --size) {
if (src[0] == '\\' && src[1] != '\0' && size > 1) {
src++;
Expand Down

0 comments on commit bbf3c7f

Please sign in to comment.