From c2676bf9e639e31e44b12a2cc82cf2046231b056 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 24 Aug 2026 11:55:29 +0200 Subject: [PATCH] vssh: silence gcc-11 `-Wnull-dereference`, dedupe `CURL_EASY_STR()` calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Silencing: ``` In file included from libcurl_unity.c:179: vssh/vssh.c: In function ‘Curl_ssh_setup_pkey.part.0’: vssh/vssh.c:423:50: error: potential null pointer dereference [-Werror=null-dereference] 423 | CURL_EASY_STR(data, STRING_SSH_PUBLIC_KEY)[0]) { libtool: compile: gcc -DHAVE_CONFIG_H -I../include -I../lib -I../lib -I. -DBUILDING_LIBCURL -DCURL_STATICLIB -DUNITTESTS -D_GNU_SOURCE -Werror-implicit-functi ``` Ref: https://app.circleci.com/pipelines/gh/curl/curl/20825/workflows/c3eb591b-5a7d-40da-baa8-d2d9980b0cb2/jobs/181277 Follow-up to c8df3defd9664cd276adc33754210ee07b5bbf71 #22628 Closes #22656 --- lib/vssh/vssh.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vssh/vssh.c b/lib/vssh/vssh.c index f8e687382c..9834546987 100644 --- a/lib/vssh/vssh.c +++ b/lib/vssh/vssh.c @@ -366,6 +366,8 @@ CURLcode Curl_ssh_setup_pkey(struct Curl_easy *data, struct ssh_conn *sshc) { char *home = NULL; if(data->set.ssh_auth_types & CURLSSH_AUTH_PUBLICKEY) { + const char *str; + sshc->pub_key = sshc->priv_key = NULL; if(CURL_EASY_STR(data, STRING_SSH_PRIVATE_KEY)) { @@ -418,11 +420,9 @@ CURLcode Curl_ssh_setup_pkey(struct Curl_easy *data, struct ssh_conn *sshc) * library extract the public key from the private key file. This is done * by passing sshc->pub_key = NULL. */ - if(CURL_EASY_STR(data, STRING_SSH_PUBLIC_KEY) && - /* treat empty string the same way as NULL */ - CURL_EASY_STR(data, STRING_SSH_PUBLIC_KEY)[0]) { - sshc->pub_key = curlx_strdup( - CURL_EASY_STR(data, STRING_SSH_PUBLIC_KEY)); + str = CURL_EASY_STR(data, STRING_SSH_PUBLIC_KEY); + if(str && *str) { /* treat empty string the same way as NULL */ + sshc->pub_key = curlx_strdup(str); if(!sshc->pub_key) goto fail; }