Skip to content

Commit 5a5bb45

Browse files
committed
[acquire/tests/test_*.h] Increase test coverage ; [*.h,cli/cli{.h,.c}] Modify code fixing issues test failures found ; [reports/test_coverage.svg] Regenerate on latest ctest run
1 parent a81dea3 commit 5a5bb45

File tree

14 files changed

+434
-358
lines changed

14 files changed

+434
-358
lines changed

acquire/acquire_libcurl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ enum acquire_status acquire_download_async_poll(struct acquire_handle *handle) {
209209
} else {
210210
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE,
211211
&response_code);
212-
if (response_code >= 400) {
212+
if (msg->data.result == CURLE_COULDNT_RESOLVE_HOST) {
213+
acquire_handle_set_error(handle, ACQUIRE_ERROR_HOST_NOT_FOUND,
214+
"Could not resolve host: %s",
215+
curl_easy_strerror(msg->data.result));
216+
} else if (response_code >= 400) {
213217
acquire_handle_set_error(handle, ACQUIRE_ERROR_HTTP_FAILURE,
214218
"HTTP error: %ld", response_code);
215219
} else {

acquire/acquire_librhash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int _librhash_verify_async_start(struct acquire_handle *handle,
7777
break;
7878
case LIBACQUIRE_SHA512:
7979
rhash_algo_id = RHASH_SHA512;
80-
expected_len = 128;
80+
expected_len = 129;
8181
break;
8282
default:
8383
return -1;

acquire/acquire_url_utils.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ char *get_path_from_url(const char *url) {
6868
return NULL;
6969

7070
last_slash = strrchr(url, '/');
71-
if (last_slash)
71+
if (last_slash) {
72+
if ((last_slash - url) < 9)
73+
return strdup("");
7274
last_slash++;
73-
else
75+
} else
7476
last_slash = url;
7577

7678
end = last_slash;
@@ -90,20 +92,12 @@ char *get_path_from_url(const char *url) {
9092
}
9193

9294
bool is_url(const char *maybe_url) {
93-
if (maybe_url == NULL || strlen(maybe_url) < 8)
94-
return false;
95-
else if (maybe_url[0] == 'h' && maybe_url[1] == 't' && maybe_url[2] == 't' &&
96-
maybe_url[3] == 'p')
97-
return (maybe_url[4] == ':' && maybe_url[5] == '/' &&
98-
maybe_url[6] == '/') ||
99-
(maybe_url[4] == 's' && maybe_url[5] == ':' && maybe_url[6] == '/' &&
100-
maybe_url[7] == '/');
101-
else if (maybe_url[0] == 'f' && maybe_url[1] == 't' && maybe_url[2] == 'p')
102-
return (maybe_url[3] == ':' && maybe_url[4] == '/' &&
103-
maybe_url[5] == '/') ||
104-
(maybe_url[3] == 's' && maybe_url[4] == ':' && maybe_url[5] == '/' &&
105-
maybe_url[6] == '/');
106-
return false /* strchr(maybe_url, '/') != NULL */;
95+
return maybe_url != NULL && strlen(maybe_url) > 5 &&
96+
(strncasecmp(maybe_url, "http://", 7) == 0 ||
97+
strncasecmp(maybe_url, "https://", 8) == 0 ||
98+
strncasecmp(maybe_url, "ftp://", 6) == 0 ||
99+
strncasecmp(maybe_url, "ftps://", 7) == 0 ||
100+
strncasecmp(maybe_url, "file://", 7) == 0);
107101
}
108102

109103
#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \

0 commit comments

Comments
 (0)