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)
12571257static int
12581258get_member_value_or_fail (cJSON * reader , const gchar * member )
12591259{
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 ))
12631263 return -1 ;
12641264
1265- return item -> valueint ;
1265+ return ret ;
12661266}
12671267
12681268static 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)
246246 }
247247 class = prefs_item -> valuestring ;
248248
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 ))
251250 {
252251 g_warning ("%s: PREF missing id attribute" , __func__ );
253252 continue ;
254253 }
255- id = prefs_item -> valueint ;
256254
257255 if ((prefs_item = cJSON_GetObjectItem (prefs_obj , "name" )) == NULL
258256 || !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)
8383 return 0 ;
8484}
8585
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+
86109/**
87110 * @brief Get an int field from a JSON object.
88111 *
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ gvm_json_string_escape (const char *, gboolean);
1717double
1818gvm_json_obj_double (cJSON * , const gchar * );
1919
20+ int
21+ gvm_json_obj_check_int (cJSON * , const gchar * , int * );
22+
2023int
2124gvm_json_obj_int (cJSON * , const gchar * );
2225
You can’t perform that action at this time.
0 commit comments