From patchwork Mon May 9 16:22:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 53671 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 081BF3856DF3 for ; Mon, 9 May 2022 16:22:49 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id F14573856DC8 for ; Mon, 9 May 2022 16:22:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F14573856DC8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from tarox.wildebeest.org (83-87-18-245.cable.dynamic.v4.ziggo.nl [83.87.18.245]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id A231C3000599; Mon, 9 May 2022 18:22:34 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 1DB9840216A6; Mon, 9 May 2022 18:22:34 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: [PATCH] debuginfod: Check all curl_easy_setopt calls Date: Mon, 9 May 2022 18:22:29 +0200 Message-Id: <20220509162229.24711-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: Mark Wielaard Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" curl_easy_setup can fail for various reasons. Add a curl_easy_setopt_ck macro to check all curl_easy_setopt calls and provides a human readable error message in verbose mode. Signed-off-by: Mark Wielaard --- debuginfod/ChangeLog | 5 +++ debuginfod/debuginfod-client.c | 61 ++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 91890786..983fd44a 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2022-05-09 Mark Wielaard + + * debuginfod-client.c (debuginfod_query_server): Add + curl_easy_setopt_ck macro, use it for all curl_easy_setopt calls. + 2022-05-09 Mark Wielaard * debuginfod-client.c (debuginfod_write_callback): Check result diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 882a809a..89208216 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -1032,43 +1032,60 @@ debuginfod_query_server (debuginfod_client *c, if (vfd >= 0) dprintf (vfd, "url %d %s\n", i, data[i].url); + /* Some boilerplate for checking curl_easy_setopt. */ +#define curl_easy_setopt_ck(H,O,P) do { \ + CURLcode curl_res = curl_easy_setopt (H,O,P); \ + if (curl_res != CURLE_OK) \ + { \ + if (vfd >= 0) \ + dprintf (vfd, \ + "Bad curl_easy_setopt: %s\n", \ + curl_easy_strerror(curl_res)); \ + rc = -EINVAL; \ + goto out2; \ + } \ + } while (0) + /* Only allow http:// + https:// + file:// so we aren't being redirected to some unsupported protocol. */ - curl_easy_setopt(data[i].handle, CURLOPT_PROTOCOLS, - CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FILE); - curl_easy_setopt(data[i].handle, CURLOPT_URL, data[i].url); + curl_easy_setopt_ck(data[i].handle, CURLOPT_PROTOCOLS, + (CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FILE)); + curl_easy_setopt_ck(data[i].handle, CURLOPT_URL, data[i].url); if (vfd >= 0) - curl_easy_setopt(data[i].handle, CURLOPT_ERRORBUFFER, data[i].errbuf); - curl_easy_setopt(data[i].handle, - CURLOPT_WRITEFUNCTION, - debuginfod_write_callback); - curl_easy_setopt(data[i].handle, CURLOPT_WRITEDATA, (void*)&data[i]); + curl_easy_setopt_ck(data[i].handle, CURLOPT_ERRORBUFFER, + data[i].errbuf); + curl_easy_setopt_ck(data[i].handle, + CURLOPT_WRITEFUNCTION, + debuginfod_write_callback); + curl_easy_setopt_ck(data[i].handle, CURLOPT_WRITEDATA, (void*)&data[i]); if (timeout > 0) { /* Make sure there is at least some progress, try to get at least 100K per timeout seconds. */ - curl_easy_setopt (data[i].handle, CURLOPT_LOW_SPEED_TIME, - timeout); - curl_easy_setopt (data[i].handle, CURLOPT_LOW_SPEED_LIMIT, - 100 * 1024L); + curl_easy_setopt_ck (data[i].handle, CURLOPT_LOW_SPEED_TIME, + timeout); + curl_easy_setopt_ck (data[i].handle, CURLOPT_LOW_SPEED_LIMIT, + 100 * 1024L); } data[i].response_data = NULL; data[i].response_data_size = 0; - curl_easy_setopt(data[i].handle, CURLOPT_FILETIME, (long) 1); - curl_easy_setopt(data[i].handle, CURLOPT_FOLLOWLOCATION, (long) 1); - curl_easy_setopt(data[i].handle, CURLOPT_FAILONERROR, (long) 1); - curl_easy_setopt(data[i].handle, CURLOPT_NOSIGNAL, (long) 1); - curl_easy_setopt(data[i].handle, CURLOPT_HEADERFUNCTION, header_callback); - curl_easy_setopt(data[i].handle, CURLOPT_HEADERDATA, (void *) &(data[i])); + curl_easy_setopt_ck(data[i].handle, CURLOPT_FILETIME, (long) 1); + curl_easy_setopt_ck(data[i].handle, CURLOPT_FOLLOWLOCATION, (long) 1); + curl_easy_setopt_ck(data[i].handle, CURLOPT_FAILONERROR, (long) 1); + curl_easy_setopt_ck(data[i].handle, CURLOPT_NOSIGNAL, (long) 1); + curl_easy_setopt_ck(data[i].handle, CURLOPT_HEADERFUNCTION, + header_callback); + curl_easy_setopt_ck(data[i].handle, CURLOPT_HEADERDATA, + (void *) &(data[i])); #if LIBCURL_VERSION_NUM >= 0x072a00 /* 7.42.0 */ - curl_easy_setopt(data[i].handle, CURLOPT_PATH_AS_IS, (long) 1); + curl_easy_setopt_ck(data[i].handle, CURLOPT_PATH_AS_IS, (long) 1); #else /* On old curl; no big deal, canonicalization here is almost the same, except perhaps for ? # type decorations at the tail. */ #endif - curl_easy_setopt(data[i].handle, CURLOPT_AUTOREFERER, (long) 1); - curl_easy_setopt(data[i].handle, CURLOPT_ACCEPT_ENCODING, ""); - curl_easy_setopt(data[i].handle, CURLOPT_HTTPHEADER, c->headers); + curl_easy_setopt_ck(data[i].handle, CURLOPT_AUTOREFERER, (long) 1); + curl_easy_setopt_ck(data[i].handle, CURLOPT_ACCEPT_ENCODING, ""); + curl_easy_setopt_ck(data[i].handle, CURLOPT_HTTPHEADER, c->headers); curl_multi_add_handle(curlm, data[i].handle); }