gas preproc: Fix UB/crashes (#186)

This commit is contained in:
cryptobro 2023-05-13 07:12:54 +03:00 committed by GitHub
parent 93a960bc7d
commit fa9e004383
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -912,6 +912,9 @@ static void expand_macro(yasm_preproc_gas *pp, macro_entry *macro, const char *a
char *end = strstr(macro->params[j], "=");
int len = (end ? (size_t)(end - macro->params[j])
: strlen(macro->params[j]));
if (!tokval.t_charptr) {
continue;
}
if (!strncmp(tokval.t_charptr, macro->params[j], len)
&& tokval.t_charptr[len] == '\0') {
/* now, find matching argument. */
@ -932,6 +935,9 @@ static void expand_macro(yasm_preproc_gas *pp, macro_entry *macro, const char *a
memcpy(line + cursor - len, value, value_length);
pp->expr.string = work = line;
pp->expr.string_cursor += delta;
if (pp->expr.symbol == tokval.t_charptr) {
tokval.t_charptr = NULL;
}
if (pp->expr.symbol) {
yasm_xfree(pp->expr.symbol);
pp->expr.symbol = NULL;