From da0e437eaa6fab3a3cc27a1425b06ed7c6f3eb97 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Thu, 10 Sep 2020 21:37:34 +0000 Subject: [PATCH] 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 --- avrpart.c | 1 + config_gram.y | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/avrpart.c b/avrpart.c index acb13d5b..4ebd4eef 100644 --- a/avrpart.c +++ b/avrpart.c @@ -254,6 +254,7 @@ AVRMEM * avr_new_memtype(void) } memset(m, 0, sizeof(*m)); + m->page_size = 1; // ensure not 0 return m; } diff --git a/config_gram.y b/config_gram.y index 0b50064f..d9f661a1 100644 --- a/config_gram.y +++ b/config_gram.y @@ -1310,7 +1310,13 @@ mem_spec : 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); } |