aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-10-19 19:29:59 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-10-19 19:29:59 +0200
commitea25a7ccad625c4e664dfd114147971b8a2677f3 (patch)
treedbbc9727140f1a0729d51fbffe0c46207cda4f9e /src
parenta3a477870cdbdb4b9c4c8b403c09b13502291234 (diff)
downloadnissy-core-ea25a7ccad625c4e664dfd114147971b8a2677f3.tar.gz
nissy-core-ea25a7ccad625c4e664dfd114147971b8a2677f3.zip
Safer handling of corrupt data
Diffstat (limited to 'src')
-rw-r--r--src/nissy.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/nissy.c b/src/nissy.c
index 793d659..c09c99e 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -13,10 +13,11 @@
13#include "solvers/solvers.h" 13#include "solvers/solvers.h"
14 14
15int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); 15int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]);
16STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]); 16STATIC bool checkdata(const char *, const tableinfo_t *);
17STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], 17STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN],
18 const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); 18 const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t);
19STATIC bool checkdata(const char *, const tableinfo_t *); 19STATIC long long write_result(cube_t, char [static NISSY_SIZE_B32]);
20STATIC size_t my_strnlen(const char *, size_t);
20 21
21#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } 22#define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F }
22struct { 23struct {
@@ -71,7 +72,8 @@ checkdata(const char *buf, const tableinfo_t *info)
71{ 72{
72 uint64_t distr[INFO_DISTRIBUTION_LEN]; 73 uint64_t distr[INFO_DISTRIBUTION_LEN];
73 74
74 if (info == NULL) { 75 if (info == NULL || my_strnlen(info->solver, INFO_SOLVER_STRLEN)
76 == INFO_SOLVER_STRLEN) {
75 LOG("checkdata: error reading table info\n"); 77 LOG("checkdata: error reading table info\n");
76 return false; 78 return false;
77 } else if (!strncmp(info->solver, "cocsep", 6)) { 79 } else if (!strncmp(info->solver, "cocsep", 6)) {
@@ -122,6 +124,18 @@ write_result(cube_t cube, char result[static NISSY_SIZE_B32])
122 return NISSY_OK; 124 return NISSY_OK;
123} 125}
124 126
127STATIC size_t
128my_strnlen(const char *str, size_t maxlen)
129{
130 size_t i;
131
132 for (i = 0; i < maxlen; i++)
133 if (str[i] == '\0')
134 return i;
135
136 return maxlen;
137}
138
125long long 139long long
126nissy_compose( 140nissy_compose(
127 const char cube[static NISSY_SIZE_B32], 141 const char cube[static NISSY_SIZE_B32],

Generated with cgit - Back to sebastiano.tronto.net