25c3b2
From 06d1b08aef94984256cad3c5a54cedb10295681f Mon Sep 17 00:00:00 2001
25c3b2
From: Jakub Martisko <jamartis@redhat.com>
25c3b2
Date: Thu, 8 Nov 2018 09:31:18 +0100
25c3b2
Subject: [PATCH] Possible unterminated string fix
25c3b2
25c3b2
---
25c3b2
 unix/unix.c   |  4 +++-
25c3b2
 unix/unxcfg.h |  2 +-
25c3b2
 unzip.c       | 12 ++++++++----
25c3b2
 zipinfo.c     | 12 ++++++++----
25c3b2
 4 files changed, 20 insertions(+), 10 deletions(-)
25c3b2
25c3b2
diff --git a/unix/unix.c b/unix/unix.c
25c3b2
index 59b622d..cd57f80 100644
25c3b2
--- a/unix/unix.c
25c3b2
+++ b/unix/unix.c
25c3b2
@@ -1945,7 +1945,9 @@ void init_conversion_charsets()
25c3b2
     	for(i = 0; i < sizeof(dos_charset_map)/sizeof(CHARSET_MAP); i++)
25c3b2
     		if(!strcasecmp(local_charset, dos_charset_map[i].local_charset)) {
25c3b2
     			strncpy(OEM_CP, dos_charset_map[i].archive_charset,
25c3b2
-    					sizeof(OEM_CP));
25c3b2
+    					MAX_CP_NAME - 1);
25c3b2
+
25c3b2
+			OEM_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     			break;
25c3b2
     		}
25c3b2
     }
25c3b2
diff --git a/unix/unxcfg.h b/unix/unxcfg.h
25c3b2
index 8729de2..9ee8cfe 100644
25c3b2
--- a/unix/unxcfg.h
25c3b2
+++ b/unix/unxcfg.h
25c3b2
@@ -228,7 +228,7 @@ typedef struct stat z_stat;
25c3b2
 /*    and notfirstcall are used by do_wild().                          */
25c3b2
 
25c3b2
 
25c3b2
-#define MAX_CP_NAME 25 
25c3b2
+#define MAX_CP_NAME 25 + 1 
25c3b2
    
25c3b2
 #ifdef SETLOCALE
25c3b2
 #  undef SETLOCALE
25c3b2
diff --git a/unzip.c b/unzip.c
25c3b2
index 2d94a38..a485f2b 100644
25c3b2
--- a/unzip.c
25c3b2
+++ b/unzip.c
25c3b2
@@ -1561,7 +1561,8 @@ int uz_opts(__G__ pargc, pargv)
25c3b2
         		                  "error:  a valid character encoding should follow the -I argument"));
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
-    						strncpy(ISO_CP, s, sizeof(ISO_CP));
25c3b2
+    						strncpy(ISO_CP, s, MAX_CP_NAME - 1);
25c3b2
+                ISO_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					} else { /* -I charset */
25c3b2
     						++argv;
25c3b2
     						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
25c3b2
@@ -1570,7 +1571,8 @@ int uz_opts(__G__ pargc, pargv)
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
     						s = *argv;
25c3b2
-    						strncpy(ISO_CP, s, sizeof(ISO_CP));
25c3b2
+    						strncpy(ISO_CP, s, MAX_CP_NAME - 1);
25c3b2
+                ISO_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					}
25c3b2
     					while(*(++s)); /* No params straight after charset name */
25c3b2
     				}
25c3b2
@@ -1665,7 +1667,8 @@ int uz_opts(__G__ pargc, pargv)
25c3b2
         		                  "error:  a valid character encoding should follow the -I argument"));
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
-    						strncpy(OEM_CP, s, sizeof(OEM_CP));
25c3b2
+    						strncpy(OEM_CP, s, MAX_CP_NAME - 1);
25c3b2
+                OEM_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					} else { /* -O charset */
25c3b2
     						++argv;
25c3b2
     						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
25c3b2
@@ -1674,7 +1677,8 @@ int uz_opts(__G__ pargc, pargv)
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
     						s = *argv;
25c3b2
-    						strncpy(OEM_CP, s, sizeof(OEM_CP));
25c3b2
+    						strncpy(OEM_CP, s, MAX_CP_NAME - 1);
25c3b2
+                OEM_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					}
25c3b2
     					while(*(++s)); /* No params straight after charset name */
25c3b2
     				}
25c3b2
diff --git a/zipinfo.c b/zipinfo.c
25c3b2
index accca2a..cb7e08d 100644
25c3b2
--- a/zipinfo.c
25c3b2
+++ b/zipinfo.c
25c3b2
@@ -519,7 +519,8 @@ int zi_opts(__G__ pargc, pargv)
25c3b2
         		                  "error:  a valid character encoding should follow the -I argument"));
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
-    						strncpy(ISO_CP, s, sizeof(ISO_CP));
25c3b2
+    						strncpy(ISO_CP, s, MAX_CP_NAME - 1);
25c3b2
+                ISO_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					} else { /* -I charset */
25c3b2
     						++argv;
25c3b2
     						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
25c3b2
@@ -528,7 +529,8 @@ int zi_opts(__G__ pargc, pargv)
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
     						s = *argv;
25c3b2
-    						strncpy(ISO_CP, s, sizeof(ISO_CP));
25c3b2
+    						strncpy(ISO_CP, s, MAX_CP_NAME - 1);
25c3b2
+                ISO_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					}
25c3b2
     					while(*(++s)); /* No params straight after charset name */
25c3b2
     				}
25c3b2
@@ -568,7 +570,8 @@ int zi_opts(__G__ pargc, pargv)
25c3b2
         		                  "error:  a valid character encoding should follow the -I argument"));
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
-    						strncpy(OEM_CP, s, sizeof(OEM_CP));
25c3b2
+    						strncpy(OEM_CP, s, MAX_CP_NAME - 1);
25c3b2
+                OEM_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					} else { /* -O charset */
25c3b2
     						++argv;
25c3b2
     						if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
25c3b2
@@ -577,7 +580,8 @@ int zi_opts(__G__ pargc, pargv)
25c3b2
     	                        return(PK_PARAM); 
25c3b2
     						}
25c3b2
     						s = *argv;
25c3b2
-    						strncpy(OEM_CP, s, sizeof(OEM_CP));
25c3b2
+    						strncpy(OEM_CP, s, MAX_CP_NAME - 1);
25c3b2
+                OEM_CP[MAX_CP_NAME - 1] = '\0';
25c3b2
     					}
25c3b2
     					while(*(++s)); /* No params straight after charset name */
25c3b2
     				}
25c3b2
-- 
25c3b2
2.14.5
25c3b2