From 503b912fa11db372db043a8b8fbce51e75b36eed Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Mon, 8 Aug 2016 09:12:53 -0400 Subject: [PATCH] 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 --- src/plugins/kdb/db2/libdb2/test/btree.tests/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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"); } -- 2.47.2