aboutsummaryrefslogtreecommitdiff
path: root/gunzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'gunzip.c')
-rw-r--r--gunzip.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/gunzip.c b/gunzip.c
index fddcc7653..db7fa1dfe 100644
--- a/gunzip.c
+++ b/gunzip.c
@@ -3,6 +3,9 @@
3 */ 3 */
4 4
5#include "internal.h" 5#include "internal.h"
6#define bb_need_name_too_long
7#define BB_DECLARE_EXTERN
8#include "messages.c"
6 9
7static const char gunzip_usage[] = 10static const char gunzip_usage[] =
8 "gunzip [OPTION]... FILE\n\n" 11 "gunzip [OPTION]... FILE\n\n"
@@ -64,6 +67,7 @@ static char *license_msg[] = {
64#include <signal.h> 67#include <signal.h>
65#include <sys/stat.h> 68#include <sys/stat.h>
66#include <errno.h> 69#include <errno.h>
70#include <sys/param.h> /* for PATH_MAX */
67 71
68/* #include "tailor.h" */ 72/* #include "tailor.h" */
69 73
@@ -627,8 +631,12 @@ typedef RETSIGTYPE (*sig_type) OF((int));
627#endif 631#endif
628#define RW_USER (S_IRUSR | S_IWUSR) /* creation mode for open() */ 632#define RW_USER (S_IRUSR | S_IWUSR) /* creation mode for open() */
629 633
630#ifndef MAX_PATH_LEN 634#ifndef MAX_PATH_LEN /* max pathname length */
631# define MAX_PATH_LEN 1024 /* max pathname length */ 635# ifdef PATH_MAX
636# define MAX_PATH_LEN PATH_MAX
637# else
638# define MAX_PATH_LEN 1024
639# endif
632#endif 640#endif
633 641
634#ifndef SEEK_END 642#ifndef SEEK_END
@@ -696,8 +704,8 @@ int gunzip_main (int argc, char** argv)
696 int delInputFile=0; 704 int delInputFile=0;
697 struct stat statBuf; 705 struct stat statBuf;
698 char* delFileName; 706 char* delFileName;
699 char ifname[MAX_PATH_LEN]; /* input file name */ 707 char ifname[MAX_PATH_LEN + 1]; /* input file name */
700 char ofname[MAX_PATH_LEN]; /* output file name */ 708 char ofname[MAX_PATH_LEN + 1]; /* output file name */
701 709
702 if (argc==1) 710 if (argc==1)
703 usage(gunzip_usage); 711 usage(gunzip_usage);
@@ -764,7 +772,11 @@ int gunzip_main (int argc, char** argv)
764 /* Open up the input file */ 772 /* Open up the input file */
765 if (*argv=='\0') 773 if (*argv=='\0')
766 usage(gunzip_usage); 774 usage(gunzip_usage);
767 strncpy(ifname, *argv, MAX_PATH_LEN); 775 if (strlen(*argv) > MAX_PATH_LEN) {
776 fprintf(stderr, name_too_long, "gunzip");
777 do_exit(WARNING);
778 }
779 strcpy(ifname, *argv);
768 780
769 /* Open input fille */ 781 /* Open input fille */
770 inFileNum=open( ifname, O_RDONLY); 782 inFileNum=open( ifname, O_RDONLY);
@@ -799,7 +811,11 @@ int gunzip_main (int argc, char** argv)
799 char* pos; 811 char* pos;
800 812
801 /* And get to work */ 813 /* And get to work */
802 strncpy(ofname, ifname, MAX_PATH_LEN-4); 814 if (strlen(ifname) > MAX_PATH_LEN - 4) {
815 fprintf(stderr, name_too_long, "gunzip");
816 do_exit(WARNING);
817 }
818 strcpy(ofname, ifname);
803 pos=strstr(ofname, ".gz"); 819 pos=strstr(ofname, ".gz");
804 if (pos != NULL) { 820 if (pos != NULL) {
805 *pos='\0'; 821 *pos='\0';