[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

@ -18,20 +18,25 @@ OpenAPI_cnf_t *OpenAPI_cnf_create(
void OpenAPI_cnf_free(OpenAPI_cnf_t *cnf)
{
OpenAPI_lnode_t *node = NULL;
if (NULL == cnf) {
return;
}
OpenAPI_lnode_t *node;
OpenAPI_list_for_each(cnf->cnf_units, node) {
OpenAPI_cnf_unit_free(node->data);
if (cnf->cnf_units) {
OpenAPI_list_for_each(cnf->cnf_units, node) {
OpenAPI_cnf_unit_free(node->data);
}
OpenAPI_list_free(cnf->cnf_units);
cnf->cnf_units = NULL;
}
OpenAPI_list_free(cnf->cnf_units);
ogs_free(cnf);
}
cJSON *OpenAPI_cnf_convertToJSON(OpenAPI_cnf_t *cnf)
{
cJSON *item = NULL;
OpenAPI_lnode_t *node = NULL;
if (cnf == NULL) {
ogs_error("OpenAPI_cnf_convertToJSON() failed [Cnf]");
@ -39,22 +44,22 @@ cJSON *OpenAPI_cnf_convertToJSON(OpenAPI_cnf_t *cnf)
}
item = cJSON_CreateObject();
if (!cnf->cnf_units) {
ogs_error("OpenAPI_cnf_convertToJSON() failed [cnf_units]");
return NULL;
}
cJSON *cnf_unitsList = cJSON_AddArrayToObject(item, "cnfUnits");
if (cnf_unitsList == NULL) {
ogs_error("OpenAPI_cnf_convertToJSON() failed [cnf_units]");
goto end;
}
OpenAPI_lnode_t *cnf_units_node;
if (cnf->cnf_units) {
OpenAPI_list_for_each(cnf->cnf_units, cnf_units_node) {
cJSON *itemLocal = OpenAPI_cnf_unit_convertToJSON(cnf_units_node->data);
if (itemLocal == NULL) {
ogs_error("OpenAPI_cnf_convertToJSON() failed [cnf_units]");
goto end;
}
cJSON_AddItemToArray(cnf_unitsList, itemLocal);
OpenAPI_list_for_each(cnf->cnf_units, node) {
cJSON *itemLocal = OpenAPI_cnf_unit_convertToJSON(node->data);
if (itemLocal == NULL) {
ogs_error("OpenAPI_cnf_convertToJSON() failed [cnf_units]");
goto end;
}
cJSON_AddItemToArray(cnf_unitsList, itemLocal);
}
end:
@ -64,43 +69,49 @@ end:
OpenAPI_cnf_t *OpenAPI_cnf_parseFromJSON(cJSON *cnfJSON)
{
OpenAPI_cnf_t *cnf_local_var = NULL;
cJSON *cnf_units = cJSON_GetObjectItemCaseSensitive(cnfJSON, "cnfUnits");
OpenAPI_lnode_t *node = NULL;
cJSON *cnf_units = NULL;
OpenAPI_list_t *cnf_unitsList = NULL;
cnf_units = cJSON_GetObjectItemCaseSensitive(cnfJSON, "cnfUnits");
if (!cnf_units) {
ogs_error("OpenAPI_cnf_parseFromJSON() failed [cnf_units]");
goto end;
}
OpenAPI_list_t *cnf_unitsList;
cJSON *cnf_units_local_nonprimitive;
if (!cJSON_IsArray(cnf_units)){
ogs_error("OpenAPI_cnf_parseFromJSON() failed [cnf_units]");
goto end;
}
cnf_unitsList = OpenAPI_list_create();
cJSON_ArrayForEach(cnf_units_local_nonprimitive, cnf_units ) {
if (!cJSON_IsObject(cnf_units_local_nonprimitive)) {
cJSON *cnf_units_local = NULL;
if (!cJSON_IsArray(cnf_units)) {
ogs_error("OpenAPI_cnf_parseFromJSON() failed [cnf_units]");
goto end;
}
OpenAPI_cnf_unit_t *cnf_unitsItem = OpenAPI_cnf_unit_parseFromJSON(cnf_units_local_nonprimitive);
if (!cnf_unitsItem) {
ogs_error("No cnf_unitsItem");
OpenAPI_list_free(cnf_unitsList);
goto end;
cnf_unitsList = OpenAPI_list_create();
cJSON_ArrayForEach(cnf_units_local, cnf_units) {
if (!cJSON_IsObject(cnf_units_local)) {
ogs_error("OpenAPI_cnf_parseFromJSON() failed [cnf_units]");
goto end;
}
OpenAPI_cnf_unit_t *cnf_unitsItem = OpenAPI_cnf_unit_parseFromJSON(cnf_units_local);
if (!cnf_unitsItem) {
ogs_error("No cnf_unitsItem");
OpenAPI_list_free(cnf_unitsList);
goto end;
}
OpenAPI_list_add(cnf_unitsList, cnf_unitsItem);
}
OpenAPI_list_add(cnf_unitsList, cnf_unitsItem);
}
cnf_local_var = OpenAPI_cnf_create (
cnf_unitsList
);
return cnf_local_var;
end:
if (cnf_unitsList) {
OpenAPI_list_for_each(cnf_unitsList, node) {
OpenAPI_cnf_unit_free(node->data);
}
OpenAPI_list_free(cnf_unitsList);
cnf_unitsList = NULL;
}
return NULL;
}