06-with-valgrind.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. --- contrib/libs/libidn/lib/idna.c (index)
  2. +++ contrib/libs/libidn/lib/idna.c (working tree)
  3. @@ -44,6 +44,43 @@
  4. #define DOTP(c) ((c) == 0x002E || (c) == 0x3002 || \
  5. (c) == 0xFF0E || (c) == 0xFF61)
  6. +#ifdef WITH_VALGRIND
  7. +
  8. +static size_t STRLEN(const char *s) {
  9. + size_t ret = 0;
  10. + while (*s++)
  11. + ++ret;
  12. + return ret;
  13. +}
  14. +
  15. +static char* STRCPY(char* destination, const char* source) {
  16. + char *p = destination;
  17. + while (*source)
  18. + *p++ = *source++;
  19. + *p = 0;
  20. + return destination;
  21. +}
  22. +
  23. +static char* STRCAT(char* destination, const char* source) {
  24. + char *p = destination;
  25. + while (*p)
  26. + ++p;
  27. +
  28. + while (*source)
  29. + *p++ = *source++;
  30. + *p = 0;
  31. +
  32. + return destination;
  33. +}
  34. +
  35. +#else //WITH_VALGRIND
  36. +
  37. +# define STRLEN(s) strlen(s)
  38. +# define STRCAT(d, s) strcat(d, s)
  39. +# define STRCPY(d, s) strcpy(d, s)
  40. +
  41. +#endif
  42. +
  43. /* Core functions */
  44. /**
  45. @@ -51,7 +88,7 @@
  46. * @in: input array with unicode code points.
  47. * @inlen: length of input array with unicode code points.
  48. * @out: output zero terminated string that must have room for at
  49. - * least 63 characters plus the terminating zero.
  50. + * least IDNA_LABEL_MAX_LENGTH characters plus the terminating zero.
  51. * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
  52. * %IDNA_USE_STD3_ASCII_RULES.
  53. *
  54. @@ -124,7 +161,7 @@ idna_to_ascii_4i (const uint32_t * in, size_t inlen, char *out, int flags)
  55. if (p == NULL)
  56. return IDNA_MALLOC_ERROR;
  57. - len = strlen (p);
  58. + len = STRLEN (p);
  59. do
  60. {
  61. char *newp;
  62. @@ -207,13 +244,14 @@ step3:
  63. if (src[i] > 0x7F)
  64. inasciirange = 0;
  65. /* copy string to output buffer if we are about to skip to step8 */
  66. - if (i < 64)
  67. + if (i < IDNA_LABEL_MAX_LENGTH)
  68. out[i] = src[i];
  69. }
  70. - if (i < 64)
  71. + if (i < IDNA_LABEL_MAX_LENGTH)
  72. out[i] = '\0';
  73. else
  74. {
  75. + out[IDNA_LABEL_MAX_LENGTH] = 0;
  76. free (src);
  77. return IDNA_INVALID_LENGTH;
  78. }
  79. @@ -231,7 +269,7 @@ step3:
  80. int match;
  81. match = 1;
  82. - for (i = 0; match && i < strlen (IDNA_ACE_PREFIX); i++)
  83. + for (i = 0; match && i < STRLEN (IDNA_ACE_PREFIX); i++)
  84. if (((uint32_t) IDNA_ACE_PREFIX[i] & 0xFF) != src[i])
  85. match = 0;
  86. if (match)
  87. @@ -248,30 +286,30 @@ step3:
  88. for (len = 0; src[len]; len++)
  89. ;
  90. src[len] = '\0';
  91. - outlen = 63 - strlen (IDNA_ACE_PREFIX);
  92. + outlen = IDNA_LABEL_MAX_LENGTH - STRLEN (IDNA_ACE_PREFIX);
  93. rc = punycode_encode (len, src, NULL,
  94. - &outlen, &out[strlen (IDNA_ACE_PREFIX)]);
  95. + &outlen, &out[STRLEN (IDNA_ACE_PREFIX)]);
  96. if (rc != PUNYCODE_SUCCESS)
  97. {
  98. free (src);
  99. return IDNA_PUNYCODE_ERROR;
  100. }
  101. - out[strlen (IDNA_ACE_PREFIX) + outlen] = '\0';
  102. + out[STRLEN (IDNA_ACE_PREFIX) + outlen] = '\0';
  103. /*
  104. * 7. Prepend the ACE prefix.
  105. */
  106. - memcpy (out, IDNA_ACE_PREFIX, strlen (IDNA_ACE_PREFIX));
  107. + memcpy (out, IDNA_ACE_PREFIX, STRLEN (IDNA_ACE_PREFIX));
  108. /*
  109. - * 8. Verify that the number of code points is in the range 1 to 63
  110. + * 8. Verify that the number of code points is in the range 1 to IDNA_LABEL_MAX_LENGTH
  111. * inclusive (0 is excluded).
  112. */
  113. step8:
  114. free (src);
  115. - if (strlen (out) < 1)
  116. + if (STRLEN (out) < 1 || STRLEN (out) > IDNA_LABEL_MAX_LENGTH - 1)
  117. return IDNA_INVALID_LENGTH;
  118. return IDNA_SUCCESS;
  119. @@ -283,8 +321,8 @@ idna_to_unicode_internal (char *utf8in,
  120. uint32_t * out, size_t *outlen, int flags)
  121. {
  122. int rc;
  123. - char tmpout[64];
  124. - size_t utf8len = strlen (utf8in) + 1;
  125. + char tmpout[IDNA_LABEL_MAX_LENGTH + 1];
  126. + size_t utf8len = STRLEN (utf8in) + 1;
  127. size_t addlen = 0, addinc = utf8len / 10 + 1;
  128. /*
  129. @@ -343,7 +381,7 @@ idna_to_unicode_internal (char *utf8in,
  130. */
  131. step3:
  132. - if (c_strncasecmp (utf8in, IDNA_ACE_PREFIX, strlen (IDNA_ACE_PREFIX)) != 0)
  133. + if (c_strncasecmp (utf8in, IDNA_ACE_PREFIX, STRLEN (IDNA_ACE_PREFIX)) != 0)
  134. {
  135. free (utf8in);
  136. return IDNA_NO_ACE_PREFIX;
  137. @@ -352,8 +390,8 @@ step3:
  138. /* 4. Remove the ACE prefix.
  139. */
  140. - memmove (utf8in, &utf8in[strlen (IDNA_ACE_PREFIX)],
  141. - strlen (utf8in) - strlen (IDNA_ACE_PREFIX) + 1);
  142. + memmove (utf8in, &utf8in[STRLEN (IDNA_ACE_PREFIX)],
  143. + STRLEN (utf8in) - STRLEN (IDNA_ACE_PREFIX) + 1);
  144. /* 5. Decode the sequence using the decoding algorithm in [PUNYCODE]
  145. * and fail if there is an error. Save a copy of the result of
  146. @@ -362,7 +400,7 @@ step3:
  147. (*outlen)--; /* reserve one for the zero */
  148. - rc = punycode_decode (strlen (utf8in), utf8in, outlen, out, NULL);
  149. + rc = punycode_decode (STRLEN (utf8in), utf8in, outlen, out, NULL);
  150. if (rc != PUNYCODE_SUCCESS)
  151. {
  152. free (utf8in);
  153. @@ -385,7 +423,7 @@ step3:
  154. * step 3, using a case-insensitive ASCII comparison.
  155. */
  156. - if (c_strcasecmp (utf8in, tmpout + strlen (IDNA_ACE_PREFIX)) != 0)
  157. + if (c_strcasecmp (utf8in, tmpout + STRLEN (IDNA_ACE_PREFIX)) != 0)
  158. {
  159. free (utf8in);
  160. return IDNA_ROUNDTRIP_VERIFY_ERROR;
  161. @@ -478,7 +516,7 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
  162. {
  163. const uint32_t *start = input;
  164. const uint32_t *end;
  165. - char buf[64];
  166. + char buf[1<<9];
  167. char *out = NULL;
  168. int rc;
  169. @@ -493,7 +531,7 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
  170. *output = malloc (1);
  171. if (!*output)
  172. return IDNA_MALLOC_ERROR;
  173. - strcpy (*output, "");
  174. + STRCPY (*output, "");
  175. return IDNA_SUCCESS;
  176. }
  177. @@ -503,7 +541,7 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
  178. *output = malloc (2);
  179. if (!*output)
  180. return IDNA_MALLOC_ERROR;
  181. - strcpy (*output, ".");
  182. + STRCPY (*output, ".");
  183. return IDNA_SUCCESS;
  184. }
  185. @@ -532,7 +570,7 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
  186. if (out)
  187. {
  188. - size_t l = strlen (out) + 1 + strlen (buf) + 1;
  189. + size_t l = STRLEN (out) + 1 + STRLEN (buf) + 1;
  190. char *newp = realloc (out, l);
  191. if (!newp)
  192. {
  193. @@ -540,8 +578,8 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
  194. return IDNA_MALLOC_ERROR;
  195. }
  196. out = newp;
  197. - strcat (out, ".");
  198. - strcat (out, buf);
  199. + STRCAT (out, ".");
  200. + STRCAT (out, buf);
  201. }
  202. else
  203. {
  204. @@ -851,7 +889,7 @@ idna_to_unicode_lzlz (const char *input, char **output, int flags)
  205. * @IDNA_CONTAINS_MINUS: For IDNA_USE_STD3_ASCII_RULES, indicate that
  206. * the string contains a leading or trailing hyphen-minus (U+002D).
  207. * @IDNA_INVALID_LENGTH: The final output string is not within the
  208. - * (inclusive) range 1 to 63 characters.
  209. + * (inclusive) range 1 to IDNA_LABEL_MAX_LENGTH characters.
  210. * @IDNA_NO_ACE_PREFIX: The string does not contain the ACE prefix
  211. * (for ToUnicode).
  212. * @IDNA_ROUNDTRIP_VERIFY_ERROR: The ToASCII operation on output