x509asn1: return early on errors

Overhaul to make sure functions that detect errors bail out early with
error rather than trying to continue and risk hiding the problem.

Closes #8147
This commit is contained in:
Daniel Stenberg 2021-12-14 16:45:45 +01:00
parent cdc1da9120
commit c9e0549113
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 113 additions and 56 deletions

View file

@ -348,27 +348,35 @@ UNITTEST_START
CURLcode result;
const char *beg = (const char *)&cert[0];
const char *end = (const char *)&cert[sizeof(cert)];
struct Curl_easy *data = curl_easy_init();
struct Curl_easy *data;
int i;
int byte;
if(!data)
return 2;
result = Curl_extract_certinfo(data, 0, beg, end);
fail_unless(result == CURLE_OK, "Curl_extract_certinfo returned error");
/* a poor man's fuzzing of some initial data to make sure nothing bad
happens */
for(byte = 1 ; byte < 255; byte += 17) {
for(i = 0; i < 45; i++) {
char backup = cert[i];
cert[i] = (unsigned char) (byte & 0xff);
(void) Curl_extract_certinfo(data, 0, beg, end);
cert[i] = backup;
}
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl_easy_cleanup(data);
data = curl_easy_init();
if(data) {
result = Curl_extract_certinfo(data, 0, beg, end);
fail_unless(result == CURLE_OK, "Curl_extract_certinfo returned error");
/* a poor man's fuzzing of some initial data to make sure nothing bad
happens */
for(byte = 1 ; byte < 255; byte += 17) {
for(i = 0; i < 45; i++) {
char backup = cert[i];
cert[i] = (unsigned char) (byte & 0xff);
(void) Curl_extract_certinfo(data, 0, beg, end);
cert[i] = backup;
}
}
curl_easy_cleanup(data);
}
curl_global_cleanup();
}
UNITTEST_STOP