From de0e31eaeb4ee605492854a54570596e3dda293e Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Mon, 20 Feb 2023 11:31:31 +0100 Subject: [PATCH] MT#56493 Fix some defects discovered by CoverityScan Fix the following defect: *** CID 1534609: (DEADCODE) /recording-daemon/notify.c: 110 in do_notify() 104 part = curl_mime_addpart(mime); 105 curl_mime_name(part, "ngfile"); 106 if (ret != CURLE_OK) 107 goto fail; 108 curl_mime_filedata(part, req->full_filename_path); 109 if (ret != CURLE_OK) >>> CID 1534609: (DEADCODE) >>> Execution cannot reach this statement: "goto fail;". 110 goto fail; 111 curl_easy_setopt(c, CURLOPT_MIMEPOST, mime); 112 if (ret != CURLE_OK) 113 goto fail; 114 } 115 /recording-daemon/notify.c: 113 in do_notify() 107 goto fail; 108 curl_mime_filedata(part, req->full_filename_path); 109 if (ret != CURLE_OK) 110 goto fail; 111 curl_easy_setopt(c, CURLOPT_MIMEPOST, mime); 112 if (ret != CURLE_OK) >>> CID 1534609: (DEADCODE) >>> Execution cannot reach this statement: "goto fail;". 113 goto fail; 114 } 115 116 err = "performing request"; 117 ret = curl_easy_perform(c); 118 if (ret != CURLE_OK) /recording-daemon/notify.c: 107 in do_notify() 101 err = "initializing curl mime&part"; 102 curl_mimepart *part; 103 mime = curl_mime_init(c); 104 part = curl_mime_addpart(mime); 105 curl_mime_name(part, "ngfile"); 106 if (ret != CURLE_OK) >>> CID 1534609: (DEADCODE) >>> Execution cannot reach this statement: "goto fail;". 107 goto fail; 108 curl_mime_filedata(part, req->full_filename_path); 109 if (ret != CURLE_OK) 110 goto fail; 111 curl_easy_setopt(c, CURLOPT_MIMEPOST, mime); 112 if (ret != CURLE_OK) *** CID 1534608: Error handling issues (CHECKED_RETURN) /recording-daemon/notify.c: 108 in do_notify() 102 curl_mimepart *part; 103 mime = curl_mime_init(c); 104 part = curl_mime_addpart(mime); 105 curl_mime_name(part, "ngfile"); 106 if (ret != CURLE_OK) 107 goto fail; >>> CID 1534608: Error handling issues (CHECKED_RETURN) >>> Calling "curl_mime_filedata(part, req->full_filename_path)" without checking return value. >>> This library function may fail and return an error code. 108 curl_mime_filedata(part, req->full_filename_path); 109 if (ret != CURLE_OK) 110 goto fail; 111 curl_easy_setopt(c, CURLOPT_MIMEPOST, mime); 112 if (ret != CURLE_OK) 113 goto fail; *** CID 1534607: Error handling issues (CHECKED_RETURN) /recording-daemon/notify.c: 111 in do_notify() 105 curl_mime_name(part, "ngfile"); 106 if (ret != CURLE_OK) 107 goto fail; 108 curl_mime_filedata(part, req->full_filename_path); 109 if (ret != CURLE_OK) 110 goto fail; >>> CID 1534607: Error handling issues (CHECKED_RETURN) >>> Calling "curl_easy_setopt(c, _curl_opt, mime)" without checking return value. >>> This library function may fail and return an error code. 111 curl_easy_setopt(c, CURLOPT_MIMEPOST, mime); 112 if (ret != CURLE_OK) 113 goto fail; 114 } 115 116 err = "performing request"; Additionally, refactor the code in the do_notify() slightly. Change-Id: I80dd373f4ced92d90475dbcca21ee2d62f06e57e --- recording-daemon/notify.c | 62 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/recording-daemon/notify.c b/recording-daemon/notify.c index 9df9524bd..2ae169371 100644 --- a/recording-daemon/notify.c +++ b/recording-daemon/notify.c @@ -39,7 +39,7 @@ static void do_notify(void *p, void *u) { ilog(LOG_DEBUG, "Launching HTTP notification for '%s%s%s'", FMT_M(req->name)); - // set up the CURL request + /* set up the CURL request */ #if CURL_AT_LEAST_VERSION(7,56,0) curl_mime *mime = NULL; @@ -49,53 +49,45 @@ static void do_notify(void *p, void *u) { goto fail; err = "setting CURLOPT_URL"; - ret = curl_easy_setopt(c, CURLOPT_URL, notify_uri); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_URL, notify_uri)) != CURLE_OK) goto fail; - // no output + /* no output */ err = "setting CURLOPT_WRITEFUNCTION"; - ret = curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, dummy_write); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, dummy_write)) != CURLE_OK) goto fail; - // no input + /* no input */ err = "setting CURLOPT_READFUNCTION"; - ret = curl_easy_setopt(c, CURLOPT_READFUNCTION, dummy_read); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_READFUNCTION, dummy_read)) != CURLE_OK) goto fail; - // allow redirects + /* allow redirects */ err = "setting CURLOPT_FOLLOWLOCATION"; - ret = curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1)) != CURLE_OK) goto fail; - // max 5 redirects + /* max 5 redirects */ err = "setting CURLOPT_MAXREDIRS"; - ret = curl_easy_setopt(c, CURLOPT_MAXREDIRS, 5); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_MAXREDIRS, 5)) != CURLE_OK) goto fail; - // add headers + /* add headers */ err = "setting CURLOPT_HTTPHEADER"; - ret = curl_easy_setopt(c, CURLOPT_HTTPHEADER, req->headers); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_HTTPHEADER, req->headers)) != CURLE_OK) goto fail; - // POST vs GET + /* POST vs GET */ if (notify_post) { err = "setting CURLOPT_POST"; - ret = curl_easy_setopt(c, CURLOPT_POST, 1); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_POST, 1)) != CURLE_OK) goto fail; } - // cert verify (enabled by default) + /* cert verify (enabled by default) */ if (notify_nverify) { err = "setting CURLOPT_SSL_VERIFYPEER"; - ret = curl_easy_setopt(c, CURLOPT_SSL_VERIFYPEER, 0); - if (ret != CURLE_OK) + if ((ret = curl_easy_setopt(c, CURLOPT_SSL_VERIFYPEER, 0)) != CURLE_OK) goto fail; } @@ -105,34 +97,32 @@ static void do_notify(void *p, void *u) { curl_mimepart *part; mime = curl_mime_init(c); part = curl_mime_addpart(mime); - curl_mime_name(part, "ngfile"); - if (ret != CURLE_OK) + + if ((ret = curl_mime_name(part, "ngfile")) != CURLE_OK) goto fail; - curl_mime_filedata(part, req->full_filename_path); - if (ret != CURLE_OK) + + if ((ret = curl_mime_filedata(part, req->full_filename_path)) != CURLE_OK) goto fail; - curl_easy_setopt(c, CURLOPT_MIMEPOST, mime); - if (ret != CURLE_OK) + + if ((ret = curl_easy_setopt(c, CURLOPT_MIMEPOST, mime)) != CURLE_OK) goto fail; } #endif err = "performing request"; - ret = curl_easy_perform(c); - if (ret != CURLE_OK) + if ((ret = curl_easy_perform(c)) != CURLE_OK) goto fail; long code; err = "getting CURLINFO_RESPONSE_CODE"; - ret = curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &code); - if (ret != CURLE_OK) + if ((ret = curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &code)) != CURLE_OK) goto fail; err = "checking response code (not 2xx)"; if (code < 200 || code >= 300) goto fail; - // success + /* success */ ilog(LOG_NOTICE, "HTTP notification for '%s%s%s' was successful", FMT_M(req->name)); goto cleanup; @@ -142,7 +132,7 @@ fail: curl_easy_cleanup(c); if (notify_retries >= 0 && req->retries < notify_retries) { - // schedule retry + /* schedule retry */ req->retries++; if (c) ilog(LOG_DEBUG, "Failed to perform HTTP notification for '%s%s%s': "