fix(data): reject partial and malformed map data
This commit is contained in:
@@ -3,19 +3,48 @@
|
||||
void
|
||||
str_init_utf8(struct ct *t)
|
||||
{
|
||||
static char badtail[] = { 'a', (char)0x80 };
|
||||
static char incomplete[] = { (char)0xea, (char)0xb0 };
|
||||
static char overlong[] = { (char)0xc0, (char)0xaf };
|
||||
static char outofrange[] = {
|
||||
(char)0xf4, (char)0x90, (char)0x80, (char)0x80,
|
||||
};
|
||||
static char surrogate[] = {
|
||||
(char)0xed, (char)0xa0, (char)0x80,
|
||||
};
|
||||
static char unexpected[] = { (char)0x80 };
|
||||
static const struct {
|
||||
char *name;
|
||||
char *src;
|
||||
int n;
|
||||
int ok;
|
||||
char *want;
|
||||
} cases[] = {
|
||||
{ "canonical Runeerror", "\xef\xbf\xbd", 3, 1, "\xef\xbf\xbd" },
|
||||
{ "incomplete", incomplete, sizeof incomplete, 0, "" },
|
||||
{ "unexpected continuation", unexpected, sizeof unexpected, 0, "" },
|
||||
{ "overlong", overlong, sizeof overlong, 0, "" },
|
||||
{ "surrogate", surrogate, sizeof surrogate, 0, "" },
|
||||
{ "out of range", outofrange, sizeof outofrange, 0, "" },
|
||||
{ "bad tail", badtail, sizeof badtail, 0, "" },
|
||||
};
|
||||
char full[Maxrunes+2];
|
||||
char incomplete[] = { (char)0xea, (char)0xb0 };
|
||||
Str s;
|
||||
int i;
|
||||
|
||||
s = mkstr("A한😀");
|
||||
CT_EQ_INT(t, 3, s.n);
|
||||
checkstr(t, "round trip", "A한😀", &s);
|
||||
sinit(&s, incomplete, sizeof incomplete);
|
||||
CT_EQ_INT(t, 0, s.n);
|
||||
for(i = 0; i < nelem(cases); i++){
|
||||
memset(&s, 0xa5, sizeof s);
|
||||
if(sinit(&s, cases[i].src, cases[i].n) != cases[i].ok)
|
||||
CT_ERRORF(t, "%s: wrong validity", cases[i].name);
|
||||
checkstr(t, cases[i].name, cases[i].want, &s);
|
||||
}
|
||||
memset(full, 'a', sizeof full);
|
||||
full[sizeof full-1] = '\0';
|
||||
sinit(&s, full, strlen(full));
|
||||
CT_EQ_INT(t, Maxrunes, s.n);
|
||||
CT_CHECK(t, !sinit(&s, full, strlen(full)));
|
||||
CT_EQ_INT(t, 0, s.n);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -89,9 +118,9 @@ str_invalid_and_full_appends(struct ct *t)
|
||||
Str s;
|
||||
int i;
|
||||
|
||||
sinit(&s, nil, 1);
|
||||
CT_CHECK(t, !sinit(&s, nil, 1));
|
||||
CT_EQ_INT(t, 0, s.n);
|
||||
sinit(&s, "x", -1);
|
||||
CT_CHECK(t, !sinit(&s, "x", -1));
|
||||
CT_EQ_INT(t, 0, s.n);
|
||||
for(i = 0; i < Maxrunes; i++)
|
||||
s.r[i] = 'a';
|
||||
|
||||
Reference in New Issue
Block a user