Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: move assignments out of if conditions (openvasd) #890

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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_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 @@
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 @@

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 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
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