]> The Tcpdump Group git mirrors - tcpslice/commitdiff
instrument functions: Add a length check
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 10 Mar 2023 21:37:00 +0000 (22:37 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 10 Mar 2023 22:06:04 +0000 (23:06 +0100)
We need space for the '\0'.

This should fix Coverity CID 310985.

Moreover:
Use '\0' for the null character.

instrument-functions.c

index fb2314dd3f02c25561e9bca7b342b76192d10f37..aff33ccdc7e9f90d7354e81d2ade5fefae517e82 100644 (file)
@@ -114,7 +114,12 @@ static void print_debug(void *this_fn, void *call_site, action_type action)
                        perror("failed to find executable\n");
                        return;
                }
-               pgm_name[ret] = 0;
+               if (ret == sizeof(pgm_name)) {
+                       /* no space for the '\0' */
+                       printf("truncation may have occurred\n");
+                       return;
+               }
+               pgm_name[ret] = '\0';
 
                bfd_init();