commit 8a08629b9346131c75ea47d06f101c4351f03be4
parent 9fa303e2f5363225d1920ff110cf964078b25b3e
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 15 Jan 2019 16:16:40 +0100
Improved resilience on input data format
Diffstat:
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/stardis-app.c b/src/stardis-app.c
@@ -38,7 +38,7 @@ read_line(char** pb, FILE* stream)
}
/* Search idx of first occurence of comment char or EOL */
idx = strcspn(buf, "#\n\r");
- /* Remove meaningles text */
+ /* Remove meaningless text */
buf[idx] = '\0';
/* Find first text */
idx = strspn(buf, " \t");
@@ -161,14 +161,22 @@ parse_medium_line(char* line, char** stl_filename, struct description* desc)
res = RES_BAD_ARG;
goto exit;
}
+ /* Depending of the number of spaces before '"' strtok should
+ * be called once or twice */
CHK_TOK(strtok(NULL, "\""), "Tinit");
+ if(*(tk + strspn(tk, " \t")) == '\0')
+ CHK_TOK(strtok(NULL, "\""), "Tinit");
desc->d.solid.Tinit = malloc(strlen(tk) + 1);
strcpy(desc->d.solid.Tinit, tk);
/* Closing " fot Tinit; can return NULL if line ends just after "Tinit" */
tk = strtok(NULL, "\"");
/* Volumic Power is optional */
- tk = strtok(NULL, "\"");
+ if (tk && *(tk + strspn(tk, " \t")) == '\0') {
+ /* Depending of the number of spaces before '"' strtok should
+ * be called once or twice */
+ tk = strtok(NULL, "\"");
+ }
if (tk) {
desc->d.solid.power = malloc(strlen(tk) + 1);
strcpy(desc->d.solid.power, tk);
@@ -195,7 +203,11 @@ parse_medium_line(char* line, char** stl_filename, struct description* desc)
res = RES_BAD_ARG;
goto exit;
}
+ /* Depending of the number of spaces before '"' strtok should
+ * be called once or twice */
CHK_TOK(strtok(NULL, "\""), "Tinit");
+ if (*(tk + strspn(tk, " \t")) == '\0')
+ CHK_TOK(strtok(NULL, "\""), "Tinit");
desc->d.fluid.Tinit = malloc(strlen(tk) + 1);
strcpy(desc->d.fluid.Tinit, tk);
}
@@ -292,7 +304,11 @@ parse_boundary_line(char* line, char** stl_filename, struct description* desc)
res = RES_BAD_ARG;
goto exit;
}
+ /* Depending of the number of spaces before '"' strtok should
+ * be called once or twice */
CHK_TOK(strtok(NULL, "\""), "temperature");
+ if (*(tk + strspn(tk, " \t")) == '\0')
+ CHK_TOK(strtok(NULL, "\""), "temperature");
desc->d.h_boundary.T = malloc(strlen(tk) + 1);
strcpy(desc->d.h_boundary.T, tk);
}
@@ -304,7 +320,11 @@ parse_boundary_line(char* line, char** stl_filename, struct description* desc)
*stl_filename = malloc(strlen(tk) + 1);
strcpy(*stl_filename, tk);
+ /* Depending of the number of spaces before '"' strtok should
+ * be called once or twice */
CHK_TOK(strtok(NULL, "\""), "temperature");
+ if (*(tk + strspn(tk, " \t")) == '\0')
+ CHK_TOK(strtok(NULL, "\""), "temperature");
desc->d.t_boundary.T = malloc(strlen(tk) + 1);
strcpy(desc->d.t_boundary.T, tk);
@@ -337,7 +357,11 @@ parse_boundary_line(char* line, char** stl_filename, struct description* desc)
*stl_filename = malloc(strlen(tk) + 1);
strcpy(*stl_filename, tk);
+ /* Depending of the number of spaces before '"' strtok should
+ * be called once or twice */
CHK_TOK(strtok(NULL, "\""), "flux");
+ if (*(tk + strspn(tk, " \t")) == '\0')
+ CHK_TOK(strtok(NULL, "\""), "flux");
desc->d.f_boundary.flux = malloc(strlen(tk) + 1);
strcpy(desc->d.f_boundary.flux, tk);
diff --git a/src/stardis-app.h b/src/stardis-app.h
@@ -452,6 +452,7 @@ hash_t_boundary
(const struct t_boundary* key,
const enum description_type type)
{
+ (void)type;
ASSERT(type == DESC_BOUND_T_FOR_SOLID || type == DESC_BOUND_T_FOR_FLUID);
#ifdef ARCH_32BITS
/* 32-bits Fowler/Noll/Vo hash function */