]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix bttest printing of unterminated strings
authorTom Yu <tlyu@mit.edu>
Mon, 8 Aug 2016 13:12:53 +0000 (09:12 -0400)
committerTom Yu <tlyu@mit.edu>
Tue, 16 Aug 2016 19:24:27 +0000 (15:24 -0400)
The libdb2 btree debugging program bttest can attempt to print keys or
data that aren't null-terminated, reading past the end of the
length-counted byte array.  Use the "%.*s" format specifier to provide
an explicit length when printing keys or data.

ticket: 8478

src/plugins/kdb/db2/libdb2/test/btree.tests/main.c

index 2aee3a32c05eff6137f9dd5b5e69f507f0cc630b..78195d6e6768dce79489480d2791aea75decc942 100644 (file)
@@ -636,7 +636,7 @@ list(db, argv)
        }
        status = (*db->seq)(db, &key, &data, R_FIRST);
        while (status == RET_SUCCESS) {
-               (void)fprintf(fp, "%s\n", key.data);
+               (void)fprintf(fp, "%.*s\n", (int)key.size, key.data);
                status = (*db->seq)(db, &key, &data, R_NEXT);
        }
        (void)fclose(fp);
@@ -661,7 +661,7 @@ rlist(db, argv)
        }
        status = bt_rseq(db, &key, &data, &cookie, R_FIRST);
        while (status == RET_SUCCESS) {
-               (void)fprintf(fp, "%s\n", key.data);
+               (void)fprintf(fp, "%.*s\n", (int)key.size, key.data);
                status = bt_rseq(db, &key, &data, &cookie, R_NEXT);
        }
        (void)fclose(fp);
@@ -822,9 +822,9 @@ keydata(key, data)
        DBT *key, *data;
 {
        if (!recno && key->size > 0)
-               (void)printf("%s/", key->data);
+               (void)printf("%.*s/", (int)key->size, key->data);
        if (data->size > 0)
-               (void)printf("%s", data->data);
+               (void)printf("%.*s", (int)data->size, data->data);
        (void)printf("\n");
 }