1 From 06d1b08aef94984256cad3c5a54cedb10295681f Mon Sep 17 00:00:00 2001
2 From: Jakub Martisko <jamartis@redhat.com>
3 Date: Thu, 8 Nov 2018 09:31:18 +0100
4 Subject: [PATCH] Possible unterminated string fix
9 unzip.c | 12 ++++++++----
10 zipinfo.c | 12 ++++++++----
11 4 files changed, 20 insertions(+), 10 deletions(-)
13 diff --git a/unix/unix.c b/unix/unix.c
14 index 59b622d..cd57f80 100644
17 @@ -1945,7 +1945,9 @@ void init_conversion_charsets()
18 for(i = 0; i < sizeof(dos_charset_map)/sizeof(CHARSET_MAP); i++)
19 if(!strcasecmp(local_charset, dos_charset_map[i].local_charset)) {
20 strncpy(OEM_CP, dos_charset_map[i].archive_charset,
24 + OEM_CP[MAX_CP_NAME - 1] = '\0';
28 diff --git a/unix/unxcfg.h b/unix/unxcfg.h
29 index 8729de2..9ee8cfe 100644
32 @@ -228,7 +228,7 @@ typedef struct stat z_stat;
33 /* and notfirstcall are used by do_wild(). */
36 -#define MAX_CP_NAME 25
37 +#define MAX_CP_NAME 25 + 1
41 diff --git a/unzip.c b/unzip.c
42 index 2d94a38..a485f2b 100644
45 @@ -1561,7 +1561,8 @@ int uz_opts(__G__ pargc, pargv)
46 "error: a valid character encoding should follow the -I argument"));
49 - strncpy(ISO_CP, s, sizeof(ISO_CP));
50 + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
51 + ISO_CP[MAX_CP_NAME - 1] = '\0';
52 } else { /* -I charset */
54 if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
55 @@ -1570,7 +1571,8 @@ int uz_opts(__G__ pargc, pargv)
59 - strncpy(ISO_CP, s, sizeof(ISO_CP));
60 + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
61 + ISO_CP[MAX_CP_NAME - 1] = '\0';
63 while(*(++s)); /* No params straight after charset name */
65 @@ -1665,7 +1667,8 @@ int uz_opts(__G__ pargc, pargv)
66 "error: a valid character encoding should follow the -I argument"));
69 - strncpy(OEM_CP, s, sizeof(OEM_CP));
70 + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
71 + OEM_CP[MAX_CP_NAME - 1] = '\0';
72 } else { /* -O charset */
74 if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
75 @@ -1674,7 +1677,8 @@ int uz_opts(__G__ pargc, pargv)
79 - strncpy(OEM_CP, s, sizeof(OEM_CP));
80 + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
81 + OEM_CP[MAX_CP_NAME - 1] = '\0';
83 while(*(++s)); /* No params straight after charset name */
85 diff --git a/zipinfo.c b/zipinfo.c
86 index accca2a..cb7e08d 100644
89 @@ -519,7 +519,8 @@ int zi_opts(__G__ pargc, pargv)
90 "error: a valid character encoding should follow the -I argument"));
93 - strncpy(ISO_CP, s, sizeof(ISO_CP));
94 + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
95 + ISO_CP[MAX_CP_NAME - 1] = '\0';
96 } else { /* -I charset */
98 if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
99 @@ -528,7 +529,8 @@ int zi_opts(__G__ pargc, pargv)
103 - strncpy(ISO_CP, s, sizeof(ISO_CP));
104 + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
105 + ISO_CP[MAX_CP_NAME - 1] = '\0';
107 while(*(++s)); /* No params straight after charset name */
109 @@ -568,7 +570,8 @@ int zi_opts(__G__ pargc, pargv)
110 "error: a valid character encoding should follow the -I argument"));
113 - strncpy(OEM_CP, s, sizeof(OEM_CP));
114 + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
115 + OEM_CP[MAX_CP_NAME - 1] = '\0';
116 } else { /* -O charset */
118 if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
119 @@ -577,7 +580,8 @@ int zi_opts(__G__ pargc, pargv)
123 - strncpy(OEM_CP, s, sizeof(OEM_CP));
124 + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
125 + OEM_CP[MAX_CP_NAME - 1] = '\0';
127 while(*(++s)); /* No params straight after charset name */