aboutsummaryrefslogtreecommitdiffstats
path: root/lib/string_helpers.c
diff options
context:
space:
mode:
authorJustin Stitt <[email protected]>2024-08-08 21:43:56 +0000
committerKees Cook <[email protected]>2024-08-15 16:26:02 +0000
commitbbf3c7ff9dfa45be51500d23a1276991a7cd8c6e (patch)
tree0f9f1877cc36c3ecc72bad4ae289b4238c3c872f /lib/string_helpers.c
parentcoccinelle: Add rules to find str_down_up() replacements (diff)
downloadkernel-bbf3c7ff9dfa45be51500d23a1276991a7cd8c6e.tar.gz
kernel-bbf3c7ff9dfa45be51500d23a1276991a7cd8c6e.zip
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]>
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r--lib/string_helpers.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 69ba49b853c7..4f887aa62fa0 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -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++;