From c599e5371cd5596eb87a51fc2e6a6165c54dee32 Mon Sep 17 00:00:00 2001 From: fosslinux Date: Sun, 12 May 2024 22:52:17 +1000 Subject: [PATCH] Fix string validation for configurator --- seed/configurator.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/seed/configurator.c b/seed/configurator.c index bc8403ba..44a3ea8d 100644 --- a/seed/configurator.c +++ b/seed/configurator.c @@ -156,24 +156,24 @@ int set_val(Entry *entry, char *val) { } else if (entry->type == TYPE_STRING) { /* Validation rules. */ char *validation = entry->validation; - char *prev = validation; + char *next; int found = FALSE; - if (strcmp(validation, "") == 0) { - found = TRUE; - } - while (prev != NULL) { - if (prev[0] == '\0') { + while (validation != NULL) { + if (validation[0] == '\0') { break; } - validation = strchr(validation, '|'); - if (validation != NULL) { - validation[0] = '\0'; - validation += 1; - if (strcmp(prev, val) == 0) { + next = strchr(validation, '|'); + if (next == NULL) { + if (strcmp(validation, val) == 0) { + found = TRUE; + } + break; + } else { + if (strncmp(validation, val, next - validation) == 0) { found = TRUE; } } - prev = validation; + validation = next + 1; } if (found == FALSE) { fputs("Invalid input: ", stdout);