[SBI] Crash occurs when ENUM in the MAP (#2103)

This commit is contained in:
Sukchan Lee 2023-03-01 17:50:25 +09:00
parent ce668c556c
commit 969c116e77
1097 changed files with 266728 additions and 42047 deletions

View file

@ -22,22 +22,33 @@ OpenAPI_app_detection_info_t *OpenAPI_app_detection_info_create(
void OpenAPI_app_detection_info_free(OpenAPI_app_detection_info_t *app_detection_info)
{
OpenAPI_lnode_t *node = NULL;
if (NULL == app_detection_info) {
return;
}
OpenAPI_lnode_t *node;
ogs_free(app_detection_info->app_id);
ogs_free(app_detection_info->instance_id);
OpenAPI_list_for_each(app_detection_info->sdf_descriptions, node) {
OpenAPI_flow_information_free(node->data);
if (app_detection_info->app_id) {
ogs_free(app_detection_info->app_id);
app_detection_info->app_id = NULL;
}
if (app_detection_info->instance_id) {
ogs_free(app_detection_info->instance_id);
app_detection_info->instance_id = NULL;
}
if (app_detection_info->sdf_descriptions) {
OpenAPI_list_for_each(app_detection_info->sdf_descriptions, node) {
OpenAPI_flow_information_free(node->data);
}
OpenAPI_list_free(app_detection_info->sdf_descriptions);
app_detection_info->sdf_descriptions = NULL;
}
OpenAPI_list_free(app_detection_info->sdf_descriptions);
ogs_free(app_detection_info);
}
cJSON *OpenAPI_app_detection_info_convertToJSON(OpenAPI_app_detection_info_t *app_detection_info)
{
cJSON *item = NULL;
OpenAPI_lnode_t *node = NULL;
if (app_detection_info == NULL) {
ogs_error("OpenAPI_app_detection_info_convertToJSON() failed [AppDetectionInfo]");
@ -45,6 +56,10 @@ cJSON *OpenAPI_app_detection_info_convertToJSON(OpenAPI_app_detection_info_t *ap
}
item = cJSON_CreateObject();
if (!app_detection_info->app_id) {
ogs_error("OpenAPI_app_detection_info_convertToJSON() failed [app_id]");
return NULL;
}
if (cJSON_AddStringToObject(item, "appId", app_detection_info->app_id) == NULL) {
ogs_error("OpenAPI_app_detection_info_convertToJSON() failed [app_id]");
goto end;
@ -63,17 +78,13 @@ cJSON *OpenAPI_app_detection_info_convertToJSON(OpenAPI_app_detection_info_t *ap
ogs_error("OpenAPI_app_detection_info_convertToJSON() failed [sdf_descriptions]");
goto end;
}
OpenAPI_lnode_t *sdf_descriptions_node;
if (app_detection_info->sdf_descriptions) {
OpenAPI_list_for_each(app_detection_info->sdf_descriptions, sdf_descriptions_node) {
cJSON *itemLocal = OpenAPI_flow_information_convertToJSON(sdf_descriptions_node->data);
if (itemLocal == NULL) {
ogs_error("OpenAPI_app_detection_info_convertToJSON() failed [sdf_descriptions]");
goto end;
}
cJSON_AddItemToArray(sdf_descriptionsList, itemLocal);
OpenAPI_list_for_each(app_detection_info->sdf_descriptions, node) {
cJSON *itemLocal = OpenAPI_flow_information_convertToJSON(node->data);
if (itemLocal == NULL) {
ogs_error("OpenAPI_app_detection_info_convertToJSON() failed [sdf_descriptions]");
goto end;
}
cJSON_AddItemToArray(sdf_descriptionsList, itemLocal);
}
}
@ -84,63 +95,69 @@ end:
OpenAPI_app_detection_info_t *OpenAPI_app_detection_info_parseFromJSON(cJSON *app_detection_infoJSON)
{
OpenAPI_app_detection_info_t *app_detection_info_local_var = NULL;
cJSON *app_id = cJSON_GetObjectItemCaseSensitive(app_detection_infoJSON, "appId");
OpenAPI_lnode_t *node = NULL;
cJSON *app_id = NULL;
cJSON *instance_id = NULL;
cJSON *sdf_descriptions = NULL;
OpenAPI_list_t *sdf_descriptionsList = NULL;
app_id = cJSON_GetObjectItemCaseSensitive(app_detection_infoJSON, "appId");
if (!app_id) {
ogs_error("OpenAPI_app_detection_info_parseFromJSON() failed [app_id]");
goto end;
}
if (!cJSON_IsString(app_id)) {
ogs_error("OpenAPI_app_detection_info_parseFromJSON() failed [app_id]");
goto end;
}
cJSON *instance_id = cJSON_GetObjectItemCaseSensitive(app_detection_infoJSON, "instanceId");
instance_id = cJSON_GetObjectItemCaseSensitive(app_detection_infoJSON, "instanceId");
if (instance_id) {
if (!cJSON_IsString(instance_id)) {
if (!cJSON_IsString(instance_id) && !cJSON_IsNull(instance_id)) {
ogs_error("OpenAPI_app_detection_info_parseFromJSON() failed [instance_id]");
goto end;
}
}
cJSON *sdf_descriptions = cJSON_GetObjectItemCaseSensitive(app_detection_infoJSON, "sdfDescriptions");
OpenAPI_list_t *sdf_descriptionsList;
sdf_descriptions = cJSON_GetObjectItemCaseSensitive(app_detection_infoJSON, "sdfDescriptions");
if (sdf_descriptions) {
cJSON *sdf_descriptions_local_nonprimitive;
if (!cJSON_IsArray(sdf_descriptions)){
ogs_error("OpenAPI_app_detection_info_parseFromJSON() failed [sdf_descriptions]");
goto end;
}
sdf_descriptionsList = OpenAPI_list_create();
cJSON_ArrayForEach(sdf_descriptions_local_nonprimitive, sdf_descriptions ) {
if (!cJSON_IsObject(sdf_descriptions_local_nonprimitive)) {
cJSON *sdf_descriptions_local = NULL;
if (!cJSON_IsArray(sdf_descriptions)) {
ogs_error("OpenAPI_app_detection_info_parseFromJSON() failed [sdf_descriptions]");
goto end;
}
OpenAPI_flow_information_t *sdf_descriptionsItem = OpenAPI_flow_information_parseFromJSON(sdf_descriptions_local_nonprimitive);
if (!sdf_descriptionsItem) {
ogs_error("No sdf_descriptionsItem");
OpenAPI_list_free(sdf_descriptionsList);
goto end;
sdf_descriptionsList = OpenAPI_list_create();
cJSON_ArrayForEach(sdf_descriptions_local, sdf_descriptions) {
if (!cJSON_IsObject(sdf_descriptions_local)) {
ogs_error("OpenAPI_app_detection_info_parseFromJSON() failed [sdf_descriptions]");
goto end;
}
OpenAPI_flow_information_t *sdf_descriptionsItem = OpenAPI_flow_information_parseFromJSON(sdf_descriptions_local);
if (!sdf_descriptionsItem) {
ogs_error("No sdf_descriptionsItem");
OpenAPI_list_free(sdf_descriptionsList);
goto end;
}
OpenAPI_list_add(sdf_descriptionsList, sdf_descriptionsItem);
}
OpenAPI_list_add(sdf_descriptionsList, sdf_descriptionsItem);
}
}
app_detection_info_local_var = OpenAPI_app_detection_info_create (
ogs_strdup(app_id->valuestring),
instance_id ? ogs_strdup(instance_id->valuestring) : NULL,
instance_id && !cJSON_IsNull(instance_id) ? ogs_strdup(instance_id->valuestring) : NULL,
sdf_descriptions ? sdf_descriptionsList : NULL
);
return app_detection_info_local_var;
end:
if (sdf_descriptionsList) {
OpenAPI_list_for_each(sdf_descriptionsList, node) {
OpenAPI_flow_information_free(node->data);
}
OpenAPI_list_free(sdf_descriptionsList);
sdf_descriptionsList = NULL;
}
return NULL;
}