Skip to content

Commit

Permalink
Patched incorrect malloc() length calculation after strlen(), raising a
Browse files Browse the repository at this point in the history
warning: '__builtin_sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
  • Loading branch information
circulosmeos committed Nov 6, 2023
1 parent cf7a9f0 commit bb4a25d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gztool.c
Original file line number Diff line number Diff line change
Expand Up @@ -4349,7 +4349,7 @@ local int action_create_index(
(char *)(file_name + strlen(file_name) - 3) )
) {
// if gzip-file name is 'FILE.gz', output file name will be 'FILE'
char *output_filename = malloc( strlen(file_name) );
char *output_filename = malloc( strlen(file_name) + 1 );
sprintf(output_filename, "%s", file_name);
output_filename[strlen(file_name) - 3] = '\0';
printToStderr( VERBOSITY_NORMAL, "Decompressing to '%s'\n", output_filename );
Expand Down Expand Up @@ -6235,7 +6235,7 @@ int main(int argc, char **argv)
(char *)(file_name + strlen(file_name) - 3)
) {
// if gzip-file name is 'FILE.gz', output file has been 'FILE'
char *output_filename = malloc( strlen(file_name) );
char *output_filename = malloc( strlen(file_name) + 1 );
sprintf(output_filename, "%s", file_name);
output_filename[strlen(file_name) - 3] = '\0';
if ( do_not_delete_original_file == 0 ) {
Expand Down

0 comments on commit bb4a25d

Please sign in to comment.