Ensure page_size is always at least 1

This avoids potential divisions by 0, and possibly also other mistakes
in case of malformed avrdude.conf entries.

The solution is different than the one in patch #9820 but is supposed
to cover that condition as well.

patch #9820: Fix some out-of-bounds/uninitialized issues



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1436 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Joerg Wunsch 2020-09-10 21:37:34 +00:00
parent 785b0cea55
commit da0e437eaa
2 changed files with 8 additions and 1 deletions

View File

@ -254,6 +254,7 @@ AVRMEM * avr_new_memtype(void)
} }
memset(m, 0, sizeof(*m)); memset(m, 0, sizeof(*m));
m->page_size = 1; // ensure not 0
return m; return m;
} }

View File

@ -1310,7 +1310,13 @@ mem_spec :
K_PAGE_SIZE TKN_EQUAL TKN_NUMBER K_PAGE_SIZE TKN_EQUAL TKN_NUMBER
{ {
current_mem->page_size = $3->value.number; int ps = $3->value.number;
if (ps <= 0)
avrdude_message(MSG_INFO,
"%s, line %d: invalid page size %d, ignored\n",
infile, lineno, ps);
else
current_mem->page_size = ps;
free_token($3); free_token($3);
} | } |