From 182e2d45678d0487be71370c37b88daca3d2c54b Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 12 Oct 2024 16:23:05 +0200 Subject: Make gendata and co safer by checking buffer size --- test/090_tables_readwrite/00_table.in | 2 +- test/090_tables_readwrite/00_table.out | 2 +- test/090_tables_readwrite/tables_readwrite_tests.c | 8 ++++---- test/100_gendata_cocsep/gendata_cocsep_tests.c | 8 +++++--- 4 files changed, 11 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/090_tables_readwrite/00_table.in b/test/090_tables_readwrite/00_table.in index 0423662..3c2da46 100644 --- a/test/090_tables_readwrite/00_table.in +++ b/test/090_tables_readwrite/00_table.in @@ -2,7 +2,7 @@ Test solver 0 512 -100000000000 +512 12345678912345 399999999998 3393 diff --git a/test/090_tables_readwrite/00_table.out b/test/090_tables_readwrite/00_table.out index 0423662..3c2da46 100644 --- a/test/090_tables_readwrite/00_table.out +++ b/test/090_tables_readwrite/00_table.out @@ -2,7 +2,7 @@ Test solver 0 512 -100000000000 +512 12345678912345 399999999998 3393 diff --git a/test/090_tables_readwrite/tables_readwrite_tests.c b/test/090_tables_readwrite/tables_readwrite_tests.c index 9238207..01c1172 100644 --- a/test/090_tables_readwrite/tables_readwrite_tests.c +++ b/test/090_tables_readwrite/tables_readwrite_tests.c @@ -1,7 +1,7 @@ #include "../test.h" -bool readtableinfo(const void *, tableinfo_t *); -bool writetableinfo(const tableinfo_t *, void *); +bool readtableinfo(uint64_t, const char *, tableinfo_t *); +bool writetableinfo(const tableinfo_t *, uint64_t, char *); uint64_t readn(void) { char str[STRLENMAX]; @@ -70,7 +70,7 @@ void run(void) { tableinfo_t expected, actual; expected = test_readinfo(); - writetableinfo(&expected, buf); - readtableinfo(buf, &actual); + writetableinfo(&expected, INFOSIZE, buf); + readtableinfo(INFOSIZE, buf, &actual); test_writeinfo(actual); } diff --git a/test/100_gendata_cocsep/gendata_cocsep_tests.c b/test/100_gendata_cocsep/gendata_cocsep_tests.c index 296df28..91ebb52 100644 --- a/test/100_gendata_cocsep/gendata_cocsep_tests.c +++ b/test/100_gendata_cocsep/gendata_cocsep_tests.c @@ -1,10 +1,12 @@ #include "../test.h" +#define BUF_SIZE 2000000 + size_t gendata_cocsep(void *, uint64_t *, cube_t *); -bool readtableinfo(const void *, tableinfo_t *); +bool readtableinfo(uint64_t, const char *, tableinfo_t *); void run(void) { - char buf[2000000]; + char buf[BUF_SIZE]; uint32_t i; uint64_t selfsim[COCSEP_CLASSES]; cube_t rep[COCSEP_CLASSES]; @@ -12,7 +14,7 @@ void run(void) { tableinfo_t info; result = gendata_cocsep(buf, selfsim, rep); - if (!readtableinfo(buf, &info)) { + if (readtableinfo(BUF_SIZE, buf, &info) != NISSY_OK) { printf("Error reading info from table\n"); return; } -- cgit v1.3