File tree Expand file tree Collapse file tree 4 files changed +31
-7
lines changed Expand file tree Collapse file tree 4 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -1257,12 +1257,12 @@ openvasd_get_scan_status (openvasd_connector_t conn)
1257
1257
static int
1258
1258
get_member_value_or_fail (cJSON * reader , const gchar * member )
1259
1259
{
1260
- cJSON * item = NULL ;
1261
- if (( item = cJSON_GetObjectItem ( reader , member )) == NULL
1262
- && cJSON_IsNumber ( item ))
1260
+ int ret ;
1261
+
1262
+ if ( gvm_json_obj_check_int ( reader , member , & ret ))
1263
1263
return -1 ;
1264
1264
1265
- return item -> valueint ;
1265
+ return ret ;
1266
1266
}
1267
1267
1268
1268
static int
Original file line number Diff line number Diff line change @@ -246,13 +246,11 @@ add_preferences_to_nvt (nvti_t *nvt, cJSON *vt_obj)
246
246
}
247
247
class = prefs_item -> valuestring ;
248
248
249
- if ((prefs_item = cJSON_GetObjectItem (prefs_obj , "id" )) == NULL
250
- || !cJSON_IsNumber (prefs_item ))
249
+ if (gvm_json_obj_check_int (prefs_obj , "id" , & id ))
251
250
{
252
251
g_warning ("%s: PREF missing id attribute" , __func__ );
253
252
continue ;
254
253
}
255
- id = prefs_item -> valueint ;
256
254
257
255
if ((prefs_item = cJSON_GetObjectItem (prefs_obj , "name" )) == NULL
258
256
|| !cJSON_IsString (prefs_item ))
Original file line number Diff line number Diff line change @@ -83,6 +83,29 @@ gvm_json_obj_double (cJSON *obj, const gchar *key)
83
83
return 0 ;
84
84
}
85
85
86
+ /**
87
+ * @brief Get an int field from a JSON object.
88
+ *
89
+ * @param[in] obj Object
90
+ * @param[in] key Field name.
91
+ * @param[out] val Return location for int if int exists.
92
+ *
93
+ * @return 0 if such an int field exists, else 1.
94
+ */
95
+ int
96
+ gvm_json_obj_check_int (cJSON * obj , const gchar * key , int * val )
97
+ {
98
+ cJSON * item ;
99
+
100
+ item = cJSON_GetObjectItem (obj , key );
101
+ if (item && cJSON_IsNumber (item )) {
102
+ if (val )
103
+ * val = item -> valueint ;
104
+ return 0 ;
105
+ }
106
+ return 1 ;
107
+ }
108
+
86
109
/**
87
110
* @brief Get an int field from a JSON object.
88
111
*
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ gvm_json_string_escape (const char *, gboolean);
17
17
double
18
18
gvm_json_obj_double (cJSON * , const gchar * );
19
19
20
+ int
21
+ gvm_json_obj_check_int (cJSON * , const gchar * , int * );
22
+
20
23
int
21
24
gvm_json_obj_int (cJSON * , const gchar * );
22
25
You can’t perform that action at this time.
0 commit comments