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 /src/nissy.c | |
| 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 'src/nissy.c')
| -rw-r--r-- | src/nissy.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/nissy.c b/src/nissy.c index d725599..d3ff58a 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -394,8 +394,11 @@ nissy_datainfo( | |||
| 394 | { | 394 | { |
| 395 | uint8_t i; | 395 | uint8_t i; |
| 396 | tableinfo_t info; | 396 | tableinfo_t info; |
| 397 | int64_t ret; | ||
| 397 | 398 | ||
| 398 | readtableinfo(data, &info); | 399 | ret = readtableinfo(data_size, data, &info); |
| 400 | if (ret != 0) | ||
| 401 | return ret; | ||
| 399 | 402 | ||
| 400 | write("\n---------\n\n"); | 403 | write("\n---------\n\n"); |
| 401 | write("Table information for '%s'\n", info.solver); | 404 | write("Table information for '%s'\n", info.solver); |
| @@ -446,13 +449,14 @@ nissy_gendata( | |||
| 446 | return NISSY_ERROR_NULL_POINTER; | 449 | return NISSY_ERROR_NULL_POINTER; |
| 447 | } | 450 | } |
| 448 | 451 | ||
| 452 | arg.buf_size = data_size; | ||
| 449 | arg.buf = data; | 453 | arg.buf = data; |
| 450 | if (!strncmp(solver, "h48", 3)) { | 454 | if (!strncmp(solver, "h48", 3)) { |
| 451 | p = parse_h48_solver(solver, &arg.h, &arg.k); | 455 | p = parse_h48_solver(solver, &arg.h, &arg.k); |
| 452 | arg.maxdepth = 20; | 456 | arg.maxdepth = 20; |
| 453 | if (p != 0) | 457 | if (p != 0) |
| 454 | return NISSY_ERROR_UNKNOWN; | 458 | return NISSY_ERROR_UNKNOWN; |
| 455 | return (int64_t)gendata_h48(&arg); | 459 | return gendata_h48(&arg); |
| 456 | } else { | 460 | } else { |
| 457 | LOG("gendata: unknown solver %s\n", solver); | 461 | LOG("gendata: unknown solver %s\n", solver); |
| 458 | return NISSY_ERROR_INVALID_SOLVER; | 462 | return NISSY_ERROR_INVALID_SOLVER; |
| @@ -468,7 +472,10 @@ nissy_checkdata( | |||
| 468 | char *buf; | 472 | char *buf; |
| 469 | tableinfo_t info; | 473 | tableinfo_t info; |
| 470 | 474 | ||
| 471 | for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) { | 475 | for (buf = (char *)data; |
| 476 | readtableinfo(data_size, buf, &info); | ||
| 477 | buf += info.next, data_size -= info.next) | ||
| 478 | { | ||
| 472 | if (!checkdata(buf, &info)) { | 479 | if (!checkdata(buf, &info)) { |
| 473 | LOG("Error: data for %s is inconsistent with info!\n", | 480 | LOG("Error: data for %s is inconsistent with info!\n", |
| 474 | info.solver); | 481 | info.solver); |
| @@ -547,10 +554,10 @@ nissy_solve( | |||
| 547 | return NISSY_ERROR_INVALID_SOLVER; | 554 | return NISSY_ERROR_INVALID_SOLVER; |
| 548 | } else { | 555 | } else { |
| 549 | return THREADS > 1 ? | 556 | return THREADS > 1 ? |
| 550 | solve_h48_multithread(c, minmoves, | 557 | solve_h48_multithread(c, minmoves, maxmoves, |
| 551 | maxmoves, maxsols, data, sols) : | 558 | maxsols, data_size, data, sols_size, sols) : |
| 552 | solve_h48(c, minmoves, | 559 | solve_h48(c, minmoves, maxmoves, maxsols, |
| 553 | maxmoves, maxsols, data, sols); | 560 | data_size, data, sols_size, sols); |
| 554 | } | 561 | } |
| 555 | } else if (!strcmp(solver, "simple")) { | 562 | } else if (!strcmp(solver, "simple")) { |
| 556 | return solve_simple( | 563 | return solve_simple( |
