diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-12 16:23:05 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-12 16:23:05 +0200 |
| commit | 182e2d45678d0487be71370c37b88daca3d2c54b (patch) | |
| tree | 3987ecd9bade082a7b41901c2376daa73401e548 /tools | |
| parent | da8fdd4955fd24666643915a6728678e9965a0d3 (diff) | |
| download | nissy-core-182e2d45678d0487be71370c37b88daca3d2c54b.tar.gz nissy-core-182e2d45678d0487be71370c37b88daca3d2c54b.zip | |
Make gendata and co safer by checking buffer size
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/000_gendata/gendata.c | 2 | ||||
| -rw-r--r-- | tools/expected_distributions.h | 10 |
2 files changed, 6 insertions, 6 deletions
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c index 0d647f9..213852f 100644 --- a/tools/000_gendata/gendata.c +++ b/tools/000_gendata/gendata.c | |||
| @@ -19,7 +19,7 @@ run(void) { | |||
| 19 | default: | 19 | default: |
| 20 | nissy_datainfo(size, buf, write_stdout); | 20 | nissy_datainfo(size, buf, write_stdout); |
| 21 | consistent = nissy_checkdata(size, buf) == 0; | 21 | consistent = nissy_checkdata(size, buf) == 0; |
| 22 | expected = check_distribution(solver, buf); | 22 | expected = check_distribution(solver, size, buf); |
| 23 | if (consistent && expected) { | 23 | if (consistent && expected) { |
| 24 | printf("\n"); | 24 | printf("\n"); |
| 25 | printf("Generated %" PRId64 " bytes.\n", size); | 25 | printf("Generated %" PRId64 " bytes.\n", size); |
diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h index 1b97166..6ca1c90 100644 --- a/tools/expected_distributions.h +++ b/tools/expected_distributions.h | |||
| @@ -129,11 +129,11 @@ distribution_equal(const uint64_t *expected, const uint64_t *actual, int n) | |||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | static bool | 131 | static bool |
| 132 | check_cocsep(const void *data) | 132 | check_cocsep(uint64_t data_size, const void *data) |
| 133 | { | 133 | { |
| 134 | tableinfo_t info; | 134 | tableinfo_t info; |
| 135 | 135 | ||
| 136 | readtableinfo(data, &info); | 136 | readtableinfo(data_size, data, &info); |
| 137 | return distribution_equal( | 137 | return distribution_equal( |
| 138 | expected_cocsep, info.distribution, info.maxvalue); | 138 | expected_cocsep, info.distribution, info.maxvalue); |
| 139 | } | 139 | } |
| @@ -151,12 +151,12 @@ unknown_h48(uint8_t h, uint8_t k) | |||
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | STATIC bool | 153 | STATIC bool |
| 154 | check_distribution(const char *solver, const void *data) | 154 | check_distribution(const char *solver, uint64_t data_size, const void *data) |
| 155 | { | 155 | { |
| 156 | tableinfo_t info = {0}; | 156 | tableinfo_t info = {0}; |
| 157 | 157 | ||
| 158 | if (!strncmp(solver, "h48", 3)) { | 158 | if (!strncmp(solver, "h48", 3)) { |
| 159 | readtableinfo(data, &info); | 159 | readtableinfo(data_size, data, &info); |
| 160 | if (!distribution_equal( | 160 | if (!distribution_equal( |
| 161 | expected_cocsep, info.distribution, info.maxvalue)) { | 161 | expected_cocsep, info.distribution, info.maxvalue)) { |
| 162 | printf("ERROR! cocsep distribution is incorrect\n"); | 162 | printf("ERROR! cocsep distribution is incorrect\n"); |
| @@ -164,7 +164,7 @@ check_distribution(const char *solver, const void *data) | |||
| 164 | } | 164 | } |
| 165 | printf("cocsep distribution is correct\n"); | 165 | printf("cocsep distribution is correct\n"); |
| 166 | 166 | ||
| 167 | readtableinfo_n(data, 2, &info); | 167 | readtableinfo_n(data_size, data, 2, &info); |
| 168 | if (unknown_h48(info.h48h, info.bits)) | 168 | if (unknown_h48(info.h48h, info.bits)) |
| 169 | goto check_distribution_unknown; | 169 | goto check_distribution_unknown; |
| 170 | 170 | ||
