s3:registry: Fix buffer truncation issues issues with gcc8
authorAndreas Schneider <asn@samba.org>
Mon, 18 Jun 2018 08:34:27 +0000 (10:34 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 20 Jun 2018 20:22:07 +0000 (22:22 +0200)
../source3/registry/reg_perfcount.c: In function ‘reg_perfcount_get_hkpd’:
../source3/registry/reg_perfcount.c:337:29: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
   snprintf(buf, buflen,"%d%s", key_part1, key_part2);

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/registry/reg_perfcount.c

index a8f76ac66b217ff5709fd211ff2618dff21a22be..db4451ecdeb0b3f61361d02318ec7b7e45d0bd28 100644 (file)
@@ -166,13 +166,12 @@ static uint32_t _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
                                               uint32_t buffer_size)
 {
        TDB_DATA kbuf, dbuf;
-       char temp[256];
+       char temp[PERFCOUNT_MAX_LEN] = {0};
        char *buf1 = *retbuf;
        uint32_t working_size = 0;
        DATA_BLOB name_index, name;
        bool ok;
 
-       memset(temp, 0, sizeof(temp));
        snprintf(temp, sizeof(temp), "%d", keyval);
        kbuf = string_tdb_data(temp);
        dbuf = tdb_fetch(tdb, kbuf);
@@ -709,13 +708,13 @@ static bool _reg_perfcount_get_instance_info(struct PERF_INSTANCE_DEFINITION *in
                                             TDB_CONTEXT *names)
 {
        TDB_DATA key, data;
-       char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
+       char buf[PERFCOUNT_MAX_LEN] = {0};
+       char temp[32] = {0};
        smb_ucs2_t *name = NULL;
        int pad;
 
        /* First grab the instance data from the data file */
-       memset(temp, 0, PERFCOUNT_MAX_LEN);
-       snprintf(temp, PERFCOUNT_MAX_LEN, "i%d", instId);
+       snprintf(temp, sizeof(temp), "i%d", instId);
        _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
        if (!_reg_perfcount_get_counter_data(key, &data)) {
                DEBUG(3, ("_reg_perfcount_get_counter_data failed\n"));
@@ -739,8 +738,7 @@ static bool _reg_perfcount_get_instance_info(struct PERF_INSTANCE_DEFINITION *in
        SAFE_FREE(data.dptr);
 
        /* Fetch instance name */
-       memset(temp, 0, PERFCOUNT_MAX_LEN);
-       snprintf(temp, PERFCOUNT_MAX_LEN, "i%dname", instId);
+       snprintf(temp, sizeof(temp), "i%dname", instId);
        _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
        data = tdb_fetch(names, key);
        if(data.dptr == NULL)