]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib:util: Fix size of tmp array
authorAndreas Schneider <asn@samba.org>
Tue, 30 Apr 2024 11:01:20 +0000 (13:01 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 13 Jun 2024 12:25:37 +0000 (12:25 +0000)
lib/util/util.c: In function ‘dump_data_block16’:
lib/util/util.c:503:40: error: ‘%04zX’ directive output may be truncated
writing between 4 and 16 bytes into a region of size 15
[-Werror=format-truncation=]
  503 |         snprintf(tmp, sizeof(tmp), "%s[%04zX]", prefix, idx);
      |                                        ^~~~~

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/util/util.c

index 9df9837c85076045d51c2ad53307a4af604b7734..75a17d81b2269e958a187e797855efff852b92d2 100644 (file)
@@ -495,7 +495,9 @@ static void dump_data_block16(const char *prefix, size_t idx,
                              void (*cb)(const char *buf, void *private_data),
                              void *private_data)
 {
-       char tmp[16];
+       size_t prefix_len = strlen(prefix);
+       /* 16 (=%04zX) + 2 (=[]) + 1 (='\0') => 19 */
+       char tmp[prefix_len + 19];
        size_t i;
 
        SMB_ASSERT(len <= 16);