logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0028-Fix-for-CVE-2022-0529-and-CVE-2022-0530.patch (6754B)


  1. From 7c5862de85894d5387c855b5df6e5509c97f5bdf Mon Sep 17 00:00:00 2001
  2. From: "Steven M. Schweda" <sms@antinode.info>
  3. Date: Mon, 28 Apr 2025 12:57:34 -0700
  4. Subject: [PATCH] Fix for CVE-2022-0529 and CVE-2022-0530
  5. ---
  6. fileio.c | 34 +++++++++++++++++++++++++---------
  7. process.c | 55 ++++++++++++++++++++++++++++++++++++++++++++-----------
  8. 2 files changed, 69 insertions(+), 20 deletions(-)
  9. diff --git a/fileio.c b/fileio.c
  10. index 6290824..50a74fc 100644
  11. --- a/fileio.c
  12. +++ b/fileio.c
  13. @@ -171,8 +171,10 @@ static ZCONST char Far ReadError[] = "error: zipfile read error\n";
  14. static ZCONST char Far FilenameTooLongTrunc[] =
  15. "warning: filename too long--truncating.\n";
  16. #ifdef UNICODE_SUPPORT
  17. + static ZCONST char Far UFilenameCorrupt[] =
  18. + "error: Unicode filename corrupt.\n";
  19. static ZCONST char Far UFilenameTooLongTrunc[] =
  20. - "warning: Converted unicode filename too long--truncating.\n";
  21. + "warning: Converted Unicode filename too long--truncating.\n";
  22. #endif
  23. static ZCONST char Far ExtraFieldTooLong[] =
  24. "warning: extra field too long (%d). Ignoring...\n";
  25. @@ -2361,16 +2363,30 @@ int do_string(__G__ length, option) /* return PK-type error code */
  26. /* convert UTF-8 to local character set */
  27. fn = utf8_to_local_string(G.unipath_filename,
  28. G.unicode_escape_all);
  29. - /* make sure filename is short enough */
  30. - if (strlen(fn) >= FILNAMSIZ) {
  31. - fn[FILNAMSIZ - 1] = '\0';
  32. +
  33. + /* 2022-07-22 SMS, et al. CVE-2022-0530
  34. + * Detect conversion failure, emit message.
  35. + * Continue with unconverted name.
  36. + */
  37. + if (fn == NULL)
  38. + {
  39. Info(slide, 0x401, ((char *)slide,
  40. - LoadFarString(UFilenameTooLongTrunc)));
  41. - error = PK_WARN;
  42. + LoadFarString(UFilenameCorrupt)));
  43. + error = PK_ERR;
  44. + }
  45. + else
  46. + {
  47. + /* make sure filename is short enough */
  48. + if (strlen(fn) >= FILNAMSIZ) {
  49. + fn[FILNAMSIZ - 1] = '\0';
  50. + Info(slide, 0x401, ((char *)slide,
  51. + LoadFarString(UFilenameTooLongTrunc)));
  52. + error = PK_WARN;
  53. + }
  54. + /* replace filename with converted UTF-8 */
  55. + strcpy(G.filename, fn);
  56. + free(fn);
  57. }
  58. - /* replace filename with converted UTF-8 */
  59. - strcpy(G.filename, fn);
  60. - free(fn);
  61. }
  62. # endif /* UNICODE_WCHAR */
  63. if (G.unipath_filename != G.filename_full)
  64. diff --git a/process.c b/process.c
  65. index d2a846e..a7d5b87 100644
  66. --- a/process.c
  67. +++ b/process.c
  68. @@ -222,6 +222,8 @@ static ZCONST char Far ZipfileCommTrunc1[] =
  69. "\nwarning: Unicode Path version > 1\n";
  70. static ZCONST char Far UnicodeMismatchError[] =
  71. "\nwarning: Unicode Path checksum invalid\n";
  72. + static ZCONST char Far UFilenameTooLongTrunc[] =
  73. + "warning: filename too long (P1) -- truncating.\n";
  74. #endif
  75. @@ -1915,7 +1917,7 @@ int getZip64Data(__G__ ef_buf, ef_len)
  76. Sets both local header and central header fields. Not terribly clever,
  77. but it means that this procedure is only called in one place.
  78. - 2014-12-05 SMS.
  79. + 2014-12-05 SMS. (oCERT.org report.) CVE-2014-8141.
  80. Added checks to ensure that enough data are available before calling
  81. makeint64() or makelong(). Replaced various sizeof() values with
  82. simple ("4" or "8") constants. (The Zip64 structures do not depend
  83. @@ -1947,9 +1949,10 @@ int getZip64Data(__G__ ef_buf, ef_len)
  84. ef_len - EB_HEADSIZE));
  85. break;
  86. }
  87. +
  88. if (eb_id == EF_PKSZ64)
  89. {
  90. - int offset = EB_HEADSIZE;
  91. + unsigned offset = EB_HEADSIZE;
  92. if ((G.crec.ucsize == Z64FLGL) || (G.lrec.ucsize == Z64FLGL))
  93. {
  94. @@ -2046,7 +2049,7 @@ int getUnicodeData(__G__ ef_buf, ef_len)
  95. }
  96. if (eb_id == EF_UNIPATH) {
  97. - int offset = EB_HEADSIZE;
  98. + unsigned offset = EB_HEADSIZE;
  99. ush ULen = eb_len - 5;
  100. ulg chksum = CRCVAL_INITIAL;
  101. @@ -2504,16 +2507,17 @@ char *wide_to_local_string(wide_string, escape_all)
  102. int state_dependent;
  103. int wsize = 0;
  104. int max_bytes = MB_CUR_MAX;
  105. - char buf[9];
  106. + char buf[ MB_CUR_MAX+ 1]; /* ("+1" not really needed?) */
  107. char *buffer = NULL;
  108. char *local_string = NULL;
  109. + size_t buffer_size; /* CVE-2022-0529 */
  110. for (wsize = 0; wide_string[wsize]; wsize++) ;
  111. if (max_bytes < MAX_ESCAPE_BYTES)
  112. max_bytes = MAX_ESCAPE_BYTES;
  113. -
  114. - if ((buffer = (char *)malloc(wsize * max_bytes + 1)) == NULL) {
  115. + buffer_size = wsize * max_bytes + 1; /* Reused below. */
  116. + if ((buffer = (char *)malloc( buffer_size)) == NULL) {
  117. return NULL;
  118. }
  119. @@ -2551,8 +2555,28 @@ char *wide_to_local_string(wide_string, escape_all)
  120. } else {
  121. /* no MB for this wide */
  122. /* use escape for wide character */
  123. - char *escape_string = wide_to_escape_string(wide_string[i]);
  124. - strcat(buffer, escape_string);
  125. + size_t buffer_len;
  126. + size_t escape_string_len;
  127. + char *escape_string;
  128. + int err_msg = 0;
  129. +
  130. + escape_string = wide_to_escape_string(wide_string[i]);
  131. + buffer_len = strlen( buffer);
  132. + escape_string_len = strlen( escape_string);
  133. +
  134. + /* Append escape string, as space allows. */
  135. + /* 2022-07-18 SMS, et al. CVE-2022-0529 */
  136. + if (escape_string_len > buffer_size- buffer_len- 1)
  137. + {
  138. + escape_string_len = buffer_size- buffer_len- 1;
  139. + if (err_msg == 0)
  140. + {
  141. + err_msg = 1;
  142. + Info(slide, 0x401, ((char *)slide,
  143. + LoadFarString( UFilenameTooLongTrunc)));
  144. + }
  145. + }
  146. + strncat( buffer, escape_string, escape_string_len);
  147. free(escape_string);
  148. }
  149. }
  150. @@ -2604,9 +2628,18 @@ char *utf8_to_local_string(utf8_string, escape_all)
  151. ZCONST char *utf8_string;
  152. int escape_all;
  153. {
  154. - zwchar *wide = utf8_to_wide_string(utf8_string);
  155. - char *loc = wide_to_local_string(wide, escape_all);
  156. - free(wide);
  157. + zwchar *wide;
  158. + char *loc = NULL;
  159. +
  160. + wide = utf8_to_wide_string( utf8_string);
  161. +
  162. + /* 2022-07-25 SMS, et al. CVE-2022-0530 */
  163. + if (wide != NULL)
  164. + {
  165. + loc = wide_to_local_string( wide, escape_all);
  166. + free( wide);
  167. + }
  168. +
  169. return loc;
  170. }
  171. --
  172. 2.45.2