From: Guido Draheim Date: Mon, 5 Feb 2018 13:37:13 +0000 (+0100) Subject: fopen may fail for a bad name -> EXIT_ERRORS in that case #17 X-Git-Tag: v0.13.68~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=931f962ddfec0e00d6f486df2c56d9857b55944e;p=zziplib fopen may fail for a bad name -> EXIT_ERRORS in that case #17 --- diff --git a/bins/unzzipcat-big.c b/bins/unzzipcat-big.c index 6cddb1f..9723842 100644 --- a/bins/unzzipcat-big.c +++ b/bins/unzzipcat-big.c @@ -83,6 +83,7 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) static int unzzip_cat (int argc, char ** argv, int extract) { + int done = 0; int argn; FILE* disk; @@ -94,25 +95,25 @@ static int unzzip_cat (int argc, char ** argv, int extract) if (argc == 2) { /* print directory list */ - int warnings = 0; ZZIP_ENTRY* entry = zzip_entry_findfirst(disk); for (; entry ; entry = zzip_entry_findnext(entry)) { char* name = zzip_entry_strdup_name (entry); FILE* out = stdout; if (! name) { - warnings += 1; + done = EXIT_WARNINGS; continue; } if (extract) out = create_fopen(name, "w", 1); + if (! out) { + done = EXIT_ERRORS; + continue; + } unzzip_cat_file (disk, name, out); if (extract) fclose(out); free (name); } - if (warnings) { - return EXIT_WARNINGS; - } - return 0; + return done; } if (argc == 3 && !extract) @@ -137,6 +138,10 @@ static int unzzip_cat (int argc, char ** argv, int extract) { FILE* out = stdout; if (extract) out = create_fopen(name, "w", 1); + if (! out) { + done = EXIT_ERRORS; + continue; + } unzzip_cat_file (disk, name, out); if (extract) fclose(out); break; /* match loop */ @@ -144,7 +149,7 @@ static int unzzip_cat (int argc, char ** argv, int extract) free (name); } } - return 0; + return done; } int unzzip_print (int argc, char ** argv) diff --git a/bins/unzzipcat-mem.c b/bins/unzzipcat-mem.c index fde6229..ed671dc 100644 --- a/bins/unzzipcat-mem.c +++ b/bins/unzzipcat-mem.c @@ -48,7 +48,7 @@ static void unzzip_mem_disk_cat_file(ZZIP_MEM_DISK* disk, char* name, FILE* out) ZZIP_DISK_FILE* file = zzip_mem_disk_fopen (disk, name); if (file) { - char buffer[1024]; int len; + char buffer[1025]; int len; while ((len = zzip_mem_disk_fread (buffer, 1, 1024, file))) { fwrite (buffer, 1, len, out); @@ -87,6 +87,7 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) static int unzzip_cat (int argc, char ** argv, int extract) { + int done; int argn; ZZIP_MEM_DISK* disk; @@ -112,10 +113,14 @@ static int unzzip_cat (int argc, char ** argv, int extract) char* name = zzip_mem_entry_to_name (entry); FILE* out = stdout; if (extract) out = create_fopen(name, "w", 1); + if (! out) { + done = EXIT_ERRORS; + continue; + } unzzip_mem_disk_cat_file (disk, name, out); if (extract) fclose(out); } - return 0; + return done; } if (argc == 3 && !extract) @@ -140,13 +145,17 @@ static int unzzip_cat (int argc, char ** argv, int extract) { FILE* out = stdout; if (extract) out = create_fopen(name, "w", 1); + if (! out) { + done = EXIT_ERRORS; + continue; + } unzzip_mem_disk_cat_file (disk, name, out); if (extract) fclose(out); break; /* match loop */ } } } - return 0; + return done; } int unzzip_print (int argc, char ** argv) diff --git a/bins/unzzipcat-mix.c b/bins/unzzipcat-mix.c index 84f637b..c510643 100644 --- a/bins/unzzipcat-mix.c +++ b/bins/unzzipcat-mix.c @@ -98,6 +98,7 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) static int unzzip_cat (int argc, char ** argv, int extract) { + int done = 0; int argn; ZZIP_DIR* disk; @@ -122,6 +123,10 @@ static int unzzip_cat (int argc, char ** argv, int extract) char* name = entry->d_name; FILE* out = stdout; if (extract) out = create_fopen(name, "w", 1); + if (! out) { + done = EXIT_ERRORS; + continue; + } unzzip_cat_file (disk, name, out); if (extract) fclose(out); } @@ -149,6 +154,10 @@ static int unzzip_cat (int argc, char ** argv, int extract) mix_name[zip_name_len] = '/'; strcpy(mix_name + zip_name_len + 1, name); if (extract) out = create_fopen(name, "w", 1); + if (! out) { + done = EXIT_ERRORS; + continue; + } fprintf(stderr, "%s %s -> %s\n", zip_name, name, mix_name); /* 'test1.zip' 'README' -> 'test1/README' */ unzzip_cat_file (disk, mix_name, out); @@ -159,7 +168,7 @@ static int unzzip_cat (int argc, char ** argv, int extract) } } zzip_closedir(disk); - return 0; + return done; } int unzzip_print (int argc, char ** argv) diff --git a/bins/unzzipcat-zip.c b/bins/unzzipcat-zip.c index 6dcb2cf..e77f641 100644 --- a/bins/unzzipcat-zip.c +++ b/bins/unzzipcat-zip.c @@ -97,6 +97,7 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) static int unzzip_cat (int argc, char ** argv, int extract) { + int done = 0; int argn; ZZIP_DIR* disk; zzip_error_t error; @@ -121,10 +122,12 @@ static int unzzip_cat (int argc, char ** argv, int extract) char* name = entry.d_name; FILE* out = stdout; if (extract) out = create_fopen(name, "w", 1); - if (out) { - unzzip_cat_file (disk, name, out); - if (extract) fclose(out); + if (! out) { + done = EXIT_ERRORS; + continue; } + unzzip_cat_file (disk, name, out); + if (extract) fclose(out); } } else @@ -140,17 +143,19 @@ static int unzzip_cat (int argc, char ** argv, int extract) { FILE* out = stdout; if (extract) out = create_fopen(name, "w", 1); - if (out) { - unzzip_cat_file (disk, name, out); - if (extract) fclose(out); + if (! out) { + done = EXIT_ERRORS; + continue; } + unzzip_cat_file (disk, name, out); + if (extract) fclose(out); break; /* match loop */ } } } } zzip_dir_close(disk); - return 0; + return done; } int unzzip_print (int argc, char ** argv)