diff options
author | Peter Johnson <peter@tortall.net> | 2010-08-01 17:44:56 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2010-08-01 17:44:56 +0000 |
commit | 0d3b3797e57cd7ed5f5810246dbb17ea29e68d94 (patch) | |
tree | 745e72e5facf69d2587e27ec5bb4c7754c9b7c8f | |
parent | a0a5404f14061107f7b9849e651a73193b34f50e (diff) | |
download | yasm-0d3b3797e57cd7ed5f5810246dbb17ea29e68d94.tar.gz |
Fix #213: Fix gas-preproc misuse of strcpy() and uninitialized variables.
- strcpy() was being used with overlapping memory ranges; switched to memmove().
- bline->line_number was not set in one location.
Exact causes identified using valgrind.
svn path=/trunk/yasm/; revision=2348
-rw-r--r-- | modules/preprocs/gas/gas-preproc.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/modules/preprocs/gas/gas-preproc.c b/modules/preprocs/gas/gas-preproc.c index bbdd4992..86060d74 100644 --- a/modules/preprocs/gas/gas-preproc.c +++ b/modules/preprocs/gas/gas-preproc.c @@ -792,7 +792,7 @@ static void expand_macro(yasm_preproc_gas *pp, macro_entry *macro, const char *a memcpy(line + cursor - len, value, value_length); } else { memcpy(line + cursor - len, value, value_length); - strcpy(line + cursor - len + value_length, line + cursor); + memmove(line + cursor - len + value_length, line + cursor, strlen(line + cursor) + 1); } pp->expr_string = work = line; pp->expr_string_cursor += delta; @@ -806,6 +806,7 @@ static void expand_macro(yasm_preproc_gas *pp, macro_entry *macro, const char *a } bline->line = work + (pp->expr_string - work); + bline->line_number = -1; pp->expr_string = NULL; if (prev_bline) { @@ -928,7 +929,7 @@ static void kill_comments(yasm_preproc_gas *pp, char *line) return; } - strcpy(cstart, cend + 2); + memmove(cstart, cend + 2, strlen(cend + 2) + 1); pp->in_comment = FALSE; cstart = strstr(cstart, "/*"); next = 2; @@ -963,7 +964,7 @@ static void substitute_values(yasm_preproc_gas *pp, char *line) memcpy(line + cursor - len, value, value_length); } else { memcpy(line + cursor - len, value, value_length); - strcpy(line + cursor - len + value_length, line + cursor); + memmove(line + cursor - len + value_length, line + cursor, strlen(line + cursor) + 1); } pp->expr_string = line; pp->expr_string_cursor = cursor + delta; |