Skip to content

Commit

Permalink
Config: Add assertion to config integer parsing
Browse files Browse the repository at this point in the history
Make sure we allocate enough space for raw string parsing,
and add address santizer mode to set of C tests
  • Loading branch information
Alasdair committed Jan 16, 2025
1 parent 2d6d09b commit d5b37a3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/json/cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_bu
loop_end:
number_c_string[i] = '\0';

output = (unsigned char*)input_buffer->hooks.allocate(i * sizeof(char));
memcpy(output, number_c_string, i);
output = (unsigned char*)input_buffer->hooks.allocate(i * sizeof(char) + 1);
memcpy(output, number_c_string, i + 1);

number = strtod((const char*)number_c_string, (char**)&after_end);
if (number_c_string == after_end)
Expand Down
4 changes: 3 additions & 1 deletion lib/json/sail_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ void sail_config_unwrap_string(sail_string *str, const sail_config_json config)
void sail_config_unwrap_int(sail_int *n, const sail_config_json config)
{
cJSON *json = (cJSON *)config;
mpz_set_str(*n, json->valuestring, 10);
if (mpz_set_str(*n, json->valuestring, 10) == -1) {
sail_assert(false, "Failed to parse integer from configuration");
}
}

void sail_config_truncate(lbits *rop) {
Expand Down
1 change: 1 addition & 0 deletions test/c/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def test_coq(name):
xml += test_c('constant folding', '', '-Oconstant_fold', False)
#xml += test_c('monomorphised C', '-O2', '-O -Oconstant_fold -auto_mono', True)
xml += test_c('undefined behavior sanitised', '-O2 -fsanitize=undefined', '-O', False)
xml += test_c('address sanitised', '-O2 -fsanitize=address', '-O', False)

if 'cpp' in targets:
xml += test_c('unoptimized C with C++ compiler', '-xc++', '', False, compiler='c++')
Expand Down
4 changes: 3 additions & 1 deletion test/sailtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
parser.add_argument("--hide-error-output", help="Hide error information.", action='store_true')
parser.add_argument("--compact", help="Compact output.", action='store_true')
parser.add_argument("--targets", help="Targets to use (where supported).", action='append')
parser.add_argument("--test", help="Run only specified test.", action='append')
args = parser.parse_args()

def is_compact():
Expand Down Expand Up @@ -81,7 +82,8 @@ def chunks(filenames, cores):
ys = []
chunk = []
for filename in filenames:
if re.match('.+\.sail$', filename):
basename = os.path.splitext(os.path.basename(filename))[0]
if re.match('.+\.sail$', filename) and (not args.test or basename in args.test):
chunk.append(filename)
if len(chunk) >= cores:
ys.append(list(chunk))
Expand Down

0 comments on commit d5b37a3

Please sign in to comment.