Browse Source

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
pull/1623/head
Donat Zenichev 3 years ago
parent
commit
de0e31eaeb
1 changed files with 26 additions and 36 deletions
  1. +26
    -36
      recording-daemon/notify.c

+ 26
- 36
recording-daemon/notify.c View File

@ -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)); 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) #if CURL_AT_LEAST_VERSION(7,56,0)
curl_mime *mime = NULL; curl_mime *mime = NULL;
@ -49,53 +49,45 @@ static void do_notify(void *p, void *u) {
goto fail; goto fail;
err = "setting CURLOPT_URL"; 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; goto fail;
// no output
/* no output */
err = "setting CURLOPT_WRITEFUNCTION"; 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; goto fail;
// no input
/* no input */
err = "setting CURLOPT_READFUNCTION"; 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; goto fail;
// allow redirects
/* allow redirects */
err = "setting CURLOPT_FOLLOWLOCATION"; 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; goto fail;
// max 5 redirects
/* max 5 redirects */
err = "setting CURLOPT_MAXREDIRS"; 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; goto fail;
// add headers
/* add headers */
err = "setting CURLOPT_HTTPHEADER"; 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; goto fail;
// POST vs GET
/* POST vs GET */
if (notify_post) { if (notify_post) {
err = "setting CURLOPT_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; goto fail;
} }
// cert verify (enabled by default)
/* cert verify (enabled by default) */
if (notify_nverify) { if (notify_nverify) {
err = "setting CURLOPT_SSL_VERIFYPEER"; 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; goto fail;
} }
@ -105,34 +97,32 @@ static void do_notify(void *p, void *u) {
curl_mimepart *part; curl_mimepart *part;
mime = curl_mime_init(c); mime = curl_mime_init(c);
part = curl_mime_addpart(mime); 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; 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; 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; goto fail;
} }
#endif #endif
err = "performing request"; err = "performing request";
ret = curl_easy_perform(c);
if (ret != CURLE_OK)
if ((ret = curl_easy_perform(c)) != CURLE_OK)
goto fail; goto fail;
long code; long code;
err = "getting CURLINFO_RESPONSE_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; goto fail;
err = "checking response code (not 2xx)"; err = "checking response code (not 2xx)";
if (code < 200 || code >= 300) if (code < 200 || code >= 300)
goto fail; goto fail;
// success
/* success */
ilog(LOG_NOTICE, "HTTP notification for '%s%s%s' was successful", FMT_M(req->name)); ilog(LOG_NOTICE, "HTTP notification for '%s%s%s' was successful", FMT_M(req->name));
goto cleanup; goto cleanup;
@ -142,7 +132,7 @@ fail:
curl_easy_cleanup(c); curl_easy_cleanup(c);
if (notify_retries >= 0 && req->retries < notify_retries) { if (notify_retries >= 0 && req->retries < notify_retries) {
// schedule retry
/* schedule retry */
req->retries++; req->retries++;
if (c) if (c)
ilog(LOG_DEBUG, "Failed to perform HTTP notification for '%s%s%s': " ilog(LOG_DEBUG, "Failed to perform HTTP notification for '%s%s%s': "


Loading…
Cancel
Save