summaryrefslogtreecommitdiff
path: root/MirOTR
diff options
context:
space:
mode:
authoradmin@progandy.co.cc <admin@progandy.co.cc@eced67a3-f377-a0ae-92ae-d6de1850b05a>2010-09-16 12:12:06 +0000
committeradmin@progandy.co.cc <admin@progandy.co.cc@eced67a3-f377-a0ae-92ae-d6de1850b05a>2010-09-16 12:12:06 +0000
commitcfdfbb4f414dee7b65f846d098651e6ba1e33d0a (patch)
tree36ff56d9f2a64777657281b6faf03e1c30a03331 /MirOTR
parent8d7addf680fee1d83f443809d02b587b81ced704 (diff)
- fixed bug in decode_html_entities_utf8
git-svn-id: http://mirotr.googlecode.com/svn/trunk@16 eced67a3-f377-a0ae-92ae-d6de1850b05a
Diffstat (limited to 'MirOTR')
-rw-r--r--MirOTR/entities.cpp19
-rw-r--r--MirOTR/entities.h2
2 files changed, 13 insertions, 8 deletions
diff --git a/MirOTR/entities.cpp b/MirOTR/entities.cpp
index 892681b..ce11fe3 100644
--- a/MirOTR/entities.cpp
+++ b/MirOTR/entities.cpp
@@ -324,9 +324,9 @@ static size_t putc_utf8(unsigned long cp, char *buffer)
}
static _Bool parse_entity(const char *current, char **to,
- const char **from, size_t len)
+ const char **from, size_t maxlen)
{
- const char *end = (const char *)memchr(current, ';', len);
+ const char *end = (const char *)memchr(current, ';', maxlen);
if(!end) return 0;
if(current[1] == '#')
@@ -373,24 +373,27 @@ size_t decode_html_entities_utf8(char *dest, const char *src, size_t len)
const char *from = src;
const char *current;
- while((current = (const char*)memchr(from, '&', len)))
+ if (!len) len = strlen(src);
+ size_t remain = len;
+ while((current = (const char*)memchr(from, '&', len-(from-src))))
{
memcpy(to, from, (size_t)(current - from));
to += current - from;
+ //remain = len-(current-src);
- if(parse_entity(current, &to, &from, len))
+ if(parse_entity(current, &to, &from, len-(current-src)))
continue;
from = current;
*to++ = *from++;
}
- size_t remaining = strnlen(from, len);
+ remain = strnlen(from, len-(from-src));
- memcpy(to, from, remaining);
- to += remaining;
+ memcpy(to, from, remain);
+ to += remain;
- *to = 0;
+ if (src!=dest || (size_t)(to-dest) < len ) *to = 0;
return (size_t)(to - dest);
}
diff --git a/MirOTR/entities.h b/MirOTR/entities.h
index bf4c8eb..e4121dc 100644
--- a/MirOTR/entities.h
+++ b/MirOTR/entities.h
@@ -15,6 +15,8 @@ extern size_t decode_html_entities_utf8(char *dest, const char *src, size_t len)
otherwise, the output will be placed in `dest`, which should point
to a buffer big enough to hold `strlen(src) + 1` characters, while
`src` remains unchanged
+ if `len` is given, `dest` must be at least big enough
+ to hold `len + 1` characters.
the function returns the length of the decoded string
*/