Harden string processing during parsing in lexer.l, config_gram.y and otherwise

- Replace strdup(s) with cfg_strdup(funname, s) that exits on out of mem
 - Replace malloc(n) with cfg_malloc(funname, n) that exits on out of mem
 - Change multiline string scanning in lexer.l to avoid core dump
 - Remove global variables string_buf and string_bug_ptr
 - Ensure reading strings unescapes strings C-Style
 - Ensure writing strings escapes strings C-Style again

Commit looks longer than needed as unescape() and auxiliary functions needed
to be moved from term.c (not in libavrdude) to config.c (in libavrdude).
This commit is contained in:
Stefan Rueger
2022-08-09 21:20:44 +01:00
parent 8a717987ec
commit 22c4dbf23e
14 changed files with 355 additions and 402 deletions

View File

@@ -956,7 +956,7 @@ char *cmdbitstr(CMDBIT cb) {
else
space[1] = 0;
return strdup(space);
return cfg_strdup("cmdbitstr()", space);
}
@@ -998,7 +998,7 @@ char *opcode2str(OPCODE *op, int opnum, int detailed) {
int compact = 1;
if(!op)
return strdup("NULL");
return cfg_strdup("opcode2str()", "NULL");
// Can the opcode be printed in a compact way? Only if address bits are systematic.
for(int i=31; i >= 0; i--)
@@ -1033,7 +1033,7 @@ char *opcode2str(OPCODE *op, int opnum, int detailed) {
*sp++ = '"';
*sp = 0;
return strdup(space);
return cfg_strdup("opcode2str()", space);
}