Navigation Menu

Skip to content

Commit

Permalink
Fix a potential dangling pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
p-gen committed Sep 14, 2020
1 parent 38a694d commit 6c0f890
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions utf8.c
Expand Up @@ -194,8 +194,9 @@ utf8_interpret(char * s, langinfo_t * langinfo, char substitute)
else
{
int n;
char end;
size_t i;
char b[2] = { ' ', ' ' };
char b[3] = { ' ', ' ', '\0' };

/* They are valid, deduce from them the length of the sequence */
/* """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
Expand All @@ -212,10 +213,23 @@ utf8_interpret(char * s, langinfo_t * langinfo, char substitute)

for (i = 1; i < utf8_ascii_len / 2; i++)
{
int good = 1;

n = sscanf(utf8_seq_offset + 2 * i, "%c%c", &b[0], &b[1]);
sscanf(b, "%x", &byte);

if (n < 2 || (byte & 0xc0) != 0x80)
if (n == 2)
{
byte = 0;
end = '\0';
sscanf(b, "%x%c", &byte, &end);

if (byte == 0 || end != '\0' || (byte & 0xc0) != 0x80)
good = 0;
}
else
good = 0;

if (!good)
utf8_ascii_len = 2 * i; /* Force the new length according to the *
| number of valid UTF-8 bytes read. */
else
Expand Down

0 comments on commit 6c0f890

Please sign in to comment.