Skip to content

Commit 6792cbb

Browse files
committed
import: ignore non-successful HTTP codes for collecing image metadata
Previously we'd collect the data from redirects too, which wasn't particularly terrible, since these typically don't carry the data we were interested in, but it's still incorrect to do so.
1 parent 8dc0291 commit 6792cbb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/import/pull-job.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ static size_t pull_job_write_callback(void *contents, size_t size, size_t nmemb,
435435

436436
static size_t pull_job_header_callback(void *contents, size_t size, size_t nmemb, void *userdata) {
437437
_cleanup_free_ char *length = NULL, *last_modified = NULL, *etag = NULL;
438-
PullJob *j = userdata;
439438
size_t sz = size * nmemb;
439+
PullJob *j = userdata;
440+
CURLcode code;
441+
long status;
440442
int r;
441443

442444
assert(contents);
@@ -449,6 +451,18 @@ static size_t pull_job_header_callback(void *contents, size_t size, size_t nmemb
449451

450452
assert(j->state == PULL_JOB_ANALYZING);
451453

454+
code = curl_easy_getinfo(j->curl, CURLINFO_RESPONSE_CODE, &status);
455+
if (code != CURLE_OK) {
456+
log_error("Failed to retrieve response code: %s", curl_easy_strerror(code));
457+
r = -EIO;
458+
goto fail;
459+
}
460+
461+
if (status < 200 || status >= 300)
462+
/* If this is not HTTP 2xx, let's skip these headers, they are probably for
463+
* some redirect or so, and we are not interested in the headers of those. */
464+
return sz;
465+
452466
r = curl_header_strdup(contents, sz, "ETag:", &etag);
453467
if (r < 0) {
454468
log_oom();

0 commit comments

Comments
 (0)