unzip-6.0-COVSCAN-fix-unterminated-string.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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
  5. ---
  6. unix/unix.c | 4 +++-
  7. unix/unxcfg.h | 2 +-
  8. unzip.c | 12 ++++++++----
  9. zipinfo.c | 12 ++++++++----
  10. 4 files changed, 20 insertions(+), 10 deletions(-)
  11. diff --git a/unix/unix.c b/unix/unix.c
  12. index 59b622d..cd57f80 100644
  13. --- a/unix/unix.c
  14. +++ b/unix/unix.c
  15. @@ -1945,7 +1945,9 @@ void init_conversion_charsets()
  16. for(i = 0; i < sizeof(dos_charset_map)/sizeof(CHARSET_MAP); i++)
  17. if(!strcasecmp(local_charset, dos_charset_map[i].local_charset)) {
  18. strncpy(OEM_CP, dos_charset_map[i].archive_charset,
  19. - sizeof(OEM_CP));
  20. + MAX_CP_NAME - 1);
  21. +
  22. + OEM_CP[MAX_CP_NAME - 1] = '\0';
  23. break;
  24. }
  25. }
  26. diff --git a/unix/unxcfg.h b/unix/unxcfg.h
  27. index 8729de2..9ee8cfe 100644
  28. --- a/unix/unxcfg.h
  29. +++ b/unix/unxcfg.h
  30. @@ -228,7 +228,7 @@ typedef struct stat z_stat;
  31. /* and notfirstcall are used by do_wild(). */
  32. -#define MAX_CP_NAME 25
  33. +#define MAX_CP_NAME 25 + 1
  34. #ifdef SETLOCALE
  35. # undef SETLOCALE
  36. diff --git a/unzip.c b/unzip.c
  37. index 2d94a38..a485f2b 100644
  38. --- a/unzip.c
  39. +++ b/unzip.c
  40. @@ -1561,7 +1561,8 @@ int uz_opts(__G__ pargc, pargv)
  41. "error: a valid character encoding should follow the -I argument"));
  42. return(PK_PARAM);
  43. }
  44. - strncpy(ISO_CP, s, sizeof(ISO_CP));
  45. + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
  46. + ISO_CP[MAX_CP_NAME - 1] = '\0';
  47. } else { /* -I charset */
  48. ++argv;
  49. if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
  50. @@ -1570,7 +1571,8 @@ int uz_opts(__G__ pargc, pargv)
  51. return(PK_PARAM);
  52. }
  53. s = *argv;
  54. - strncpy(ISO_CP, s, sizeof(ISO_CP));
  55. + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
  56. + ISO_CP[MAX_CP_NAME - 1] = '\0';
  57. }
  58. while(*(++s)); /* No params straight after charset name */
  59. }
  60. @@ -1665,7 +1667,8 @@ int uz_opts(__G__ pargc, pargv)
  61. "error: a valid character encoding should follow the -I argument"));
  62. return(PK_PARAM);
  63. }
  64. - strncpy(OEM_CP, s, sizeof(OEM_CP));
  65. + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
  66. + OEM_CP[MAX_CP_NAME - 1] = '\0';
  67. } else { /* -O charset */
  68. ++argv;
  69. if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
  70. @@ -1674,7 +1677,8 @@ int uz_opts(__G__ pargc, pargv)
  71. return(PK_PARAM);
  72. }
  73. s = *argv;
  74. - strncpy(OEM_CP, s, sizeof(OEM_CP));
  75. + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
  76. + OEM_CP[MAX_CP_NAME - 1] = '\0';
  77. }
  78. while(*(++s)); /* No params straight after charset name */
  79. }
  80. diff --git a/zipinfo.c b/zipinfo.c
  81. index accca2a..cb7e08d 100644
  82. --- a/zipinfo.c
  83. +++ b/zipinfo.c
  84. @@ -519,7 +519,8 @@ int zi_opts(__G__ pargc, pargv)
  85. "error: a valid character encoding should follow the -I argument"));
  86. return(PK_PARAM);
  87. }
  88. - strncpy(ISO_CP, s, sizeof(ISO_CP));
  89. + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
  90. + ISO_CP[MAX_CP_NAME - 1] = '\0';
  91. } else { /* -I charset */
  92. ++argv;
  93. if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
  94. @@ -528,7 +529,8 @@ int zi_opts(__G__ pargc, pargv)
  95. return(PK_PARAM);
  96. }
  97. s = *argv;
  98. - strncpy(ISO_CP, s, sizeof(ISO_CP));
  99. + strncpy(ISO_CP, s, MAX_CP_NAME - 1);
  100. + ISO_CP[MAX_CP_NAME - 1] = '\0';
  101. }
  102. while(*(++s)); /* No params straight after charset name */
  103. }
  104. @@ -568,7 +570,8 @@ int zi_opts(__G__ pargc, pargv)
  105. "error: a valid character encoding should follow the -I argument"));
  106. return(PK_PARAM);
  107. }
  108. - strncpy(OEM_CP, s, sizeof(OEM_CP));
  109. + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
  110. + OEM_CP[MAX_CP_NAME - 1] = '\0';
  111. } else { /* -O charset */
  112. ++argv;
  113. if(!(--argc > 0 && *argv != NULL && **argv != '-')) {
  114. @@ -577,7 +580,8 @@ int zi_opts(__G__ pargc, pargv)
  115. return(PK_PARAM);
  116. }
  117. s = *argv;
  118. - strncpy(OEM_CP, s, sizeof(OEM_CP));
  119. + strncpy(OEM_CP, s, MAX_CP_NAME - 1);
  120. + OEM_CP[MAX_CP_NAME - 1] = '\0';
  121. }
  122. while(*(++s)); /* No params straight after charset name */
  123. }
  124. --
  125. 2.14.5