Skip to content

Commit eb1909a

Browse files
committed
fix: catch all curl_slist_append failures
There was a place were the curl_slist_append failure was not caught.
1 parent 6cfa1c3 commit eb1909a

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct curl_slist *pg_text_array_to_slist(ArrayType *array,
8080
}
8181

8282
hdr = TextDatumGetCString(value);
83-
headers = curl_slist_append(headers, hdr);
83+
CURL_SLIST_APPEND(headers, hdr);
8484
pfree(hdr);
8585
}
8686
array_free_iterator(iterator);

src/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
ereport(ERROR, errmsg("Could not curl_easy_getinfo(%s)", #opt)); \
1414
} while (0)
1515

16+
#define CURL_SLIST_APPEND(list, str) \
17+
do { \
18+
struct curl_slist *new_list = curl_slist_append(list, str); \
19+
if (new_list == NULL) \
20+
ereport(ERROR, errmsg("curl_slist_append returned NULL")); \
21+
list = new_list; \
22+
} while (0)
23+
1624
#define EREPORT_NULL_ATTR(tupIsNull, attr) \
1725
do { \
1826
if (tupIsNull) \

src/worker.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ static void init_curl_handle(CURLM *curl_mhandle, CurlData *cdata, char *url, ch
203203
ereport(ERROR, errmsg("curl_multi_add_handle returned %s", curl_multi_strerror(code)));
204204
}
205205

206-
207206
static void consume_request_queue(CURLM *curl_mhandle){
208207
int ret_code = SPI_execute_with_args("\
209208
WITH\
@@ -245,28 +244,26 @@ static void consume_request_queue(CURLM *curl_mhandle){
245244

246245
CurlData *cdata = palloc(sizeof(CurlData));
247246

248-
struct curl_slist *request_headers = NULL;
249247
Datum headersBin = SPI_getbinval(SPI_tuptable->vals[j], SPI_tuptable->tupdesc, 5, &tupIsNull);
250248

251249
if (!tupIsNull) {
252250
ArrayType *pgHeaders = DatumGetArrayTypeP(headersBin);
251+
struct curl_slist *request_headers = NULL;
252+
253253
request_headers = pg_text_array_to_slist(pgHeaders, request_headers);
254+
255+
CURL_SLIST_APPEND(request_headers, "User-Agent: pg_net/" EXTVERSION);
256+
257+
cdata->request_headers = request_headers;
254258
}
255259

256260
char *reqBody = NULL;
257261
Datum bodyBin = SPI_getbinval(SPI_tuptable->vals[j], SPI_tuptable->tupdesc, 6, &tupIsNull);
258262
if (!tupIsNull) reqBody = TextDatumGetCString(bodyBin);
259263

260-
261264
cdata->body = makeStringInfo();
262265
cdata->id = id;
263266

264-
struct curl_slist *new_headers = curl_slist_append(request_headers, "User-Agent: pg_net/" EXTVERSION);
265-
if(new_headers == NULL)
266-
ereport(ERROR, errmsg("curl_slist_append returned NULL"));
267-
268-
cdata->request_headers = new_headers;
269-
270267
init_curl_handle(curl_mhandle, cdata, url, reqBody, method, timeout_milliseconds);
271268
}
272269
}

0 commit comments

Comments
 (0)