From: Tom Yu Date: Mon, 8 Aug 2016 13:12:53 +0000 (-0400) Subject: Fix bttest printing of unterminated strings X-Git-Tag: krb5-1.15-beta1~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=503b912fa11db372db043a8b8fbce51e75b36eed;p=thirdparty%2Fkrb5.git Fix bttest printing of unterminated strings 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 --- diff --git a/src/plugins/kdb/db2/libdb2/test/btree.tests/main.c b/src/plugins/kdb/db2/libdb2/test/btree.tests/main.c index 2aee3a32c0..78195d6e67 100644 --- a/src/plugins/kdb/db2/libdb2/test/btree.tests/main.c +++ b/src/plugins/kdb/db2/libdb2/test/btree.tests/main.c @@ -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"); }