debuginfod: sqlite3_sharedprefix_fn should not compare past end of string
authorMark Wielaard <mark@klomp.org>
Sat, 4 Dec 2021 12:07:04 +0000 (13:07 +0100)
committerMark Wielaard <mark@klomp.org>
Sun, 5 Dec 2021 17:20:26 +0000 (18:20 +0100)
gcc address sanitizer detected a read after the end of string in
sqlite3_sharedprefix_fn. Make sure to stop comparing the strings when
seeing the zero terminator.

Signed-off-by: Mark Wielaard <mark@klomp.org>
debuginfod/debuginfod.cxx

index 0bbaae9..0d3f029 100644 (file)
@@ -3707,7 +3707,7 @@ static void sqlite3_sharedprefix_fn (sqlite3_context* c, int argc, sqlite3_value
       const unsigned char* a = sqlite3_value_text (argv[0]);
       const unsigned char* b = sqlite3_value_text (argv[1]);
       int i = 0;
-      while (*a++ == *b++)
+      while (*a != '\0' && *b != '\0' && *a++ == *b++)
         i++;
       sqlite3_result_int (c, i);
     }