Skip to content

Commit

Permalink
Change: move assignments out of if conditions (openvasd)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell committed Feb 13, 2025
1 parent c014fb0 commit d21a9fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
37 changes: 23 additions & 14 deletions openvasd/openvasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ handler (openvasd_connector_t conn, openvasd_req_method_t method, gchar *path,
return NULL;
}

if ((curl = curl_easy_init ()) == NULL)
curl = curl_easy_init ();

Check warning on line 424 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L424

Added line #L424 was not covered by tests
if (curl == NULL)
{
*err =
g_strdup ("{\"error\": \"Not possible to initialize curl library\"}");
Expand Down Expand Up @@ -562,9 +563,10 @@ openvasd_send_request (CURL *curl, const gchar *header_name,
openvasd_resp_t response)
{
long http_code = RESP_CODE_ERR;
int ret;

int ret = CURLE_OK;
if ((ret = curl_easy_perform (curl)) != CURLE_OK)
ret = curl_easy_perform (curl);

Check warning on line 568 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L568

Added line #L568 was not covered by tests
if (ret != CURLE_OK)
{
g_warning ("%s: Error sending request: %d", __func__, ret);
curl_easy_cleanup (curl);
Expand Down Expand Up @@ -1090,13 +1092,14 @@ openvasd_result_free (openvasd_result_t result)
static int
parse_results (const gchar *body, GSList **results)
{
cJSON *parser = NULL;
cJSON *parser;
cJSON *result_obj = NULL;
const gchar *err = NULL;
openvasd_result_t result = NULL;
int ret = -1;

if ((parser = cJSON_Parse (body)) == NULL)
parser = cJSON_Parse (body);
if (parser == NULL)
{
err = cJSON_GetErrorPtr ();
goto res_cleanup;
Expand All @@ -1109,7 +1112,7 @@ parse_results (const gchar *body, GSList **results)

cJSON_ArrayForEach (result_obj, parser)
{
cJSON *item = NULL;
cJSON *item;
gchar *detail_name = NULL;
gchar *detail_value = NULL;
gchar *detail_source_type = NULL;
Expand All @@ -1120,7 +1123,8 @@ parse_results (const gchar *body, GSList **results)
// error
goto res_cleanup;

if ((item = cJSON_GetObjectItem (result_obj, "detail")) != NULL
item = cJSON_GetObjectItem (result_obj, "detail");
if (item != NULL
&& cJSON_IsObject (item))
{
cJSON *detail_obj = NULL;
Expand Down Expand Up @@ -1283,7 +1287,8 @@ openvasd_get_scan_progress_ext (openvasd_connector_t conn,
goto cleanup;
}

if ((reader = cJSON_GetObjectItem (parser, "host_info")) == NULL)
reader = cJSON_GetObjectItem (parser, "host_info");

Check warning on line 1290 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1290

Added line #L1290 was not covered by tests
if (reader == NULL)
{
goto cleanup;
}
Expand All @@ -1303,8 +1308,9 @@ openvasd_get_scan_progress_ext (openvasd_connector_t conn,
finished = get_member_value_or_fail (reader, "finished");

// read progress of single running hosts
cJSON *scanning = NULL;
if ((scanning = cJSON_GetObjectItem (reader, "scanning")) != NULL
cJSON *scanning;
scanning = cJSON_GetObjectItem (reader, "scanning");

Check warning on line 1312 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1312

Added line #L1312 was not covered by tests
if (scanning != NULL
&& cJSON_IsObject (scanning))
{
cJSON *host = scanning->child;
Expand Down Expand Up @@ -1367,14 +1373,15 @@ get_status_code_from_openvas (const gchar *status_val)
static int
parse_status (const gchar *body, openvasd_scan_status_t status_info)
{
cJSON *parser = NULL;
cJSON *parser;
gchar *status_val = NULL;
openvasd_status_t status_code = OPENVASD_SCAN_STATUS_ERROR;

if (!status_info)
return -1;

if ((parser = cJSON_Parse (body)) == NULL)
parser = cJSON_Parse (body);
if (parser == NULL)
return -1;

if (gvm_json_obj_check_str (parser, "status", &status_val))
Expand Down Expand Up @@ -1755,7 +1762,8 @@ openvasd_parsed_scans_preferences (openvasd_connector_t conn, GSList **params)
return -1;

// No results. No information.
if ((parser = cJSON_Parse (resp->body)) == NULL || !cJSON_IsArray (parser))
parser = cJSON_Parse (resp->body);

Check warning on line 1765 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1765

Added line #L1765 was not covered by tests
if (parser == NULL || !cJSON_IsArray (parser))
{
err = 1;
goto prefs_cleanup;
Expand All @@ -1769,7 +1777,8 @@ openvasd_parsed_scans_preferences (openvasd_connector_t conn, GSList **params)
char buf[6];
cJSON *item = NULL;

if ((item = cJSON_GetObjectItem (param_obj, "default")) != NULL)
item = cJSON_GetObjectItem (param_obj, "default");

Check warning on line 1780 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1780

Added line #L1780 was not covered by tests
if (item != NULL)
{
if (cJSON_IsNumber (item))
{
Expand Down
12 changes: 8 additions & 4 deletions openvasd/vtparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ add_tags_to_nvt (nvti_t *nvt, cJSON *tag_obj)
static void
parse_references (nvti_t *nvt, cJSON *vt_obj)
{
cJSON *item = NULL;
if ((item = cJSON_GetObjectItem (vt_obj, "references")) != NULL
cJSON *item;

item = cJSON_GetObjectItem (vt_obj, "references");
if (item != NULL
&& cJSON_IsArray (item))
{
cJSON *ref_obj;
Expand All @@ -192,8 +194,10 @@ parse_references (nvti_t *nvt, cJSON *vt_obj)
static void
add_preferences_to_nvt (nvti_t *nvt, cJSON *vt_obj)
{
cJSON *item = NULL;
if ((item = cJSON_GetObjectItem (vt_obj, "preferences")) != NULL)
cJSON *item;

item = cJSON_GetObjectItem (vt_obj, "preferences");
if (item != NULL)
{
if (!cJSON_IsArray (item))
g_debug ("%s: Error reading VT/REFS array", __func__);
Expand Down

0 comments on commit d21a9fe

Please sign in to comment.