]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod: Make sure suffix can place zero terminator when copying filename
authorMark Wielaard <mark@klomp.org>
Tue, 16 Jun 2020 21:56:45 +0000 (23:56 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 24 Jun 2020 14:37:35 +0000 (16:37 +0200)
We need to make sure that we can always place a zero terminator at
the end of suffix when we are copying the filename. So add one more
char to the suffix array. And make sure that we can always add an
extra escape character when we need to escape the current character.

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

index 66511a3f1ca3dc047de7e485eb944ac7ec1d3771..9ff2e11178432ac247857b81688e058b74e9017e 100644 (file)
@@ -1,3 +1,8 @@
+2020-06-16  Mark Wielaard  <mark@klomp.org>
+
+       * debuginfod-client.c (debuginfod_query_server): Increase suffix
+       array and prepare having to escape 1 character with 2.
+
 2020-06-16  Mark Wielaard  <mark@klomp.org>
 
        * debuginfod-client.c (debuginfod_clean_cache): Handle failing
index 0cfc6dfc8879cb8da0bcb9f72b04221ad18cf53b..e9c2ca839f468ce70dad6de6a8cc3f6fa43da10c 100644 (file)
@@ -474,7 +474,7 @@ debuginfod_query_server (debuginfod_client *c,
   char *target_cache_dir = NULL;
   char *target_cache_path = NULL;
   char *target_cache_tmppath = NULL;
-  char suffix[PATH_MAX];
+  char suffix[PATH_MAX + 1]; /* +1 for zero terminator.  */
   char build_id_bytes[MAX_BUILD_ID_BYTES * 2 + 1];
   int rc;
 
@@ -511,7 +511,7 @@ debuginfod_query_server (debuginfod_client *c,
 
       /* copy the filename to suffix, s,/,#,g */
       unsigned q = 0;
-      for (unsigned fi=0; q < PATH_MAX-1; fi++)
+      for (unsigned fi=0; q < PATH_MAX-2; fi++) /* -2, escape is 2 chars.  */
         switch (filename[fi])
           {
           case '\0':