Enforce correct length of target string constraints in strncpy().

Clang did warn about these.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1438 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Joerg Wunsch 2020-09-10 21:43:23 +00:00
parent 60529b4e50
commit b23c506cbd
2 changed files with 7 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2020-09-10 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* config_gram.y (K_DESC): Enforce correct length in strncpy()
* config_gram.y (K_MEMORY): (Dito.)
2020-09-10 Joerg Wunsch <j.gnu@uriah.heep.sax.de> 2020-09-10 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* avrpart.c (avr_new_memtype): ensure page_size is at least 1 * avrpart.c (avr_new_memtype): ensure page_size is at least 1

View File

@ -672,7 +672,7 @@ part_parm :
K_DESC TKN_EQUAL TKN_STRING K_DESC TKN_EQUAL TKN_STRING
{ {
strncpy(current_part->desc, $3->value.string, AVR_DESCLEN); strncpy(current_part->desc, $3->value.string, AVR_DESCLEN - 1);
current_part->desc[AVR_DESCLEN-1] = 0; current_part->desc[AVR_DESCLEN-1] = 0;
free_token($3); free_token($3);
} | } |
@ -1240,7 +1240,7 @@ part_parm :
free_token($2); free_token($2);
YYABORT; YYABORT;
} }
strncpy(current_mem->desc, $2->value.string, AVR_MEMDESCLEN); strncpy(current_mem->desc, $2->value.string, AVR_MEMDESCLEN - 1);
current_mem->desc[AVR_MEMDESCLEN-1] = 0; current_mem->desc[AVR_MEMDESCLEN-1] = 0;
free_token($2); free_token($2);
} }