summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2020-08-08 12:38:42 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2020-08-08 12:38:42 +0200
commit1e1d6345661c21ff09e1301048d7fce59152e99b (patch)
treed8a053064fdde0b6c8710873dd6078f2495d61f6
parent974d01c5c157138e1b7138da7876a220016bf033 (diff)
Stricter check in UTFsize()
-rw-r--r--src/file_txt.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/file_txt.c b/src/file_txt.c
index 52484d8..83efab3 100644
--- a/src/file_txt.c
+++ b/src/file_txt.c
@@ -659,7 +659,9 @@ int UTFsize(const unsigned char *buffer, const unsigned int buf_len)
/* Reject some invalid UTF-8 sequences */
if(*p==0xc0 || *p==0xc1 || *p==0xf7 || *p>=0xfd)
return i;
- if((*p & 0xf0)==0xe0 && (i+2 >= buf_len || ((*(p+1) & 0xc0)==0x80 && (*(p+2) & 0xc0)==0x80)))
+ if((*p & 0xf0)==0xe0 &&
+ (i+1 >= buf_len || (*(p+1) & 0xc0)==0x80) &&
+ (i+2 >= buf_len || (*(p+2) & 0xc0)==0x80))
{ /* UTF8 l=3 */
#ifdef DEBUG_TXT
log_info("UTFsize i=%u l=3\n", i);
@@ -667,7 +669,8 @@ int UTFsize(const unsigned char *buffer, const unsigned int buf_len)
p+=3;
i+=3;
}
- else if((*p & 0xe0)==0xc0 && (i+1 >= buf_len || (*(p+1) & 0xc0)==0x80))
+ else if((*p & 0xe0)==0xc0 &&
+ (i+1 >= buf_len || (*(p+1) & 0xc0)==0x80))
{ /* UTF8 l=2 */
#ifdef DEBUG_TXT
log_info("UTFsize i=%u l=2\n", i);