summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-12-20 22:47:53 +0100
committerChristian Grothoff <christian@grothoff.org>2018-12-20 22:47:53 +0100
commitb405d707b36e0654900cba78e89f49779efea110 (patch)
tree34d4fb490f297d3eb2ebb79990e9b4dfe44c5a5f
parent69c6e75967b5f27751b0442f297f342ebc222315 (diff)
fix #5493 (out of bounds read)
-rw-r--r--src/common/convert.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/common/convert.c b/src/common/convert.c
index c0edf21..2be2108 100644
--- a/src/common/convert.c
+++ b/src/common/convert.c
@@ -36,8 +36,8 @@
* string is returned.
*/
char *
-EXTRACTOR_common_convert_to_utf8 (const char *input,
- size_t len,
+EXTRACTOR_common_convert_to_utf8 (const char *input,
+ size_t len,
const char *charset)
{
#if HAVE_ICONV
@@ -52,7 +52,7 @@ EXTRACTOR_common_convert_to_utf8 (const char *input,
i = input;
cd = iconv_open ("UTF-8", charset);
if (cd == (iconv_t) - 1)
- return strdup (i);
+ return strndup (i, len);
if (len > 1024 * 1024)
{
iconv_close (cd);
@@ -67,11 +67,11 @@ EXTRACTOR_common_convert_to_utf8 (const char *input,
}
itmp = tmp;
finSize = tmpSize;
- if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == SIZE_MAX)
+ if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == ((size_t) -1))
{
iconv_close (cd);
free (tmp);
- return strdup (i);
+ return strndup (i, len);
}
ret = malloc (tmpSize - finSize + 1);
if (ret == NULL)
https://gnunet.org