mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-19 19:33:38 +08:00
fix: correct UTF-8 continuation byte validation
This commit is contained in:
@@ -1281,7 +1281,7 @@ static int asn1_utf8char_from_bytes(uint32_t *c, const uint8_t **pin, size_t *pi
|
|||||||
|
|
||||||
utf8char = in[0];
|
utf8char = in[0];
|
||||||
for (i = 1; i < utf8char_len; i++) {
|
for (i = 1; i < utf8char_len; i++) {
|
||||||
if ((in[i] & 0x60) != 0x80) {
|
if ((in[i] & 0xc0) != 0x80) {
|
||||||
//error_print(); // disable error_print for _is_ compare
|
//error_print(); // disable error_print for _is_ compare
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -500,7 +500,10 @@ static int test_asn1_utf8_string(void)
|
|||||||
"hello",
|
"hello",
|
||||||
"world",
|
"world",
|
||||||
"Just do it!",
|
"Just do it!",
|
||||||
|
"J\303\274rgen",
|
||||||
|
"\344\270\255",
|
||||||
};
|
};
|
||||||
|
const char invalid_utf8[] = { (char)0xc3, 'A' };
|
||||||
uint8_t buf[256];
|
uint8_t buf[256];
|
||||||
uint8_t *p = buf;
|
uint8_t *p = buf;
|
||||||
const uint8_t *cp = buf;
|
const uint8_t *cp = buf;
|
||||||
@@ -530,6 +533,10 @@ static int test_asn1_utf8_string(void)
|
|||||||
error_print();
|
error_print();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (asn1_string_is_utf8_string(invalid_utf8, sizeof(invalid_utf8)) != 0) {
|
||||||
|
error_print();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
printf("%s() ok\n", __FUNCTION__);
|
printf("%s() ok\n", __FUNCTION__);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -841,6 +848,7 @@ static int test_asn1_from_der_null_args(void)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
if (test_asn1_tag() != 1) goto err;
|
if (test_asn1_tag() != 1) goto err;
|
||||||
|
if (test_asn1_utf8_string() != 1) goto err;
|
||||||
/*
|
/*
|
||||||
if (test_asn1_length() != 1) goto err;
|
if (test_asn1_length() != 1) goto err;
|
||||||
if (test_asn1_length_from_ber() != 1) goto err;
|
if (test_asn1_length_from_ber() != 1) goto err;
|
||||||
|
|||||||
Reference in New Issue
Block a user