Skip to content

Commit

Permalink
Fix bttest printing of unterminated strings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tlyu committed Aug 16, 2016
1 parent dbf6e70 commit 503b912
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/plugins/kdb/db2/libdb2/test/btree.tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit 503b912

Please sign in to comment.