[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

@ -26,20 +26,34 @@ OpenAPI_change_item_t *OpenAPI_change_item_create(
void OpenAPI_change_item_free(OpenAPI_change_item_t *change_item)
{
OpenAPI_lnode_t *node = NULL;
if (NULL == change_item) {
return;
}
OpenAPI_lnode_t *node;
ogs_free(change_item->path);
ogs_free(change_item->from);
OpenAPI_any_type_free(change_item->orig_value);
OpenAPI_any_type_free(change_item->new_value);
if (change_item->path) {
ogs_free(change_item->path);
change_item->path = NULL;
}
if (change_item->from) {
ogs_free(change_item->from);
change_item->from = NULL;
}
if (change_item->orig_value) {
OpenAPI_any_type_free(change_item->orig_value);
change_item->orig_value = NULL;
}
if (change_item->new_value) {
OpenAPI_any_type_free(change_item->new_value);
change_item->new_value = NULL;
}
ogs_free(change_item);
}
cJSON *OpenAPI_change_item_convertToJSON(OpenAPI_change_item_t *change_item)
{
cJSON *item = NULL;
OpenAPI_lnode_t *node = NULL;
if (change_item == NULL) {
ogs_error("OpenAPI_change_item_convertToJSON() failed [ChangeItem]");
@ -47,11 +61,19 @@ cJSON *OpenAPI_change_item_convertToJSON(OpenAPI_change_item_t *change_item)
}
item = cJSON_CreateObject();
if (change_item->op == OpenAPI_change_type_NULL) {
ogs_error("OpenAPI_change_item_convertToJSON() failed [op]");
return NULL;
}
if (cJSON_AddStringToObject(item, "op", OpenAPI_change_type_ToString(change_item->op)) == NULL) {
ogs_error("OpenAPI_change_item_convertToJSON() failed [op]");
goto end;
}
if (!change_item->path) {
ogs_error("OpenAPI_change_item_convertToJSON() failed [path]");
return NULL;
}
if (cJSON_AddStringToObject(item, "path", change_item->path) == NULL) {
ogs_error("OpenAPI_change_item_convertToJSON() failed [path]");
goto end;
@ -97,49 +119,50 @@ end:
OpenAPI_change_item_t *OpenAPI_change_item_parseFromJSON(cJSON *change_itemJSON)
{
OpenAPI_change_item_t *change_item_local_var = NULL;
cJSON *op = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "op");
OpenAPI_lnode_t *node = NULL;
cJSON *op = NULL;
OpenAPI_change_type_e opVariable = 0;
cJSON *path = NULL;
cJSON *from = NULL;
cJSON *orig_value = NULL;
OpenAPI_any_type_t *orig_value_local_object = NULL;
cJSON *new_value = NULL;
OpenAPI_any_type_t *new_value_local_object = NULL;
op = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "op");
if (!op) {
ogs_error("OpenAPI_change_item_parseFromJSON() failed [op]");
goto end;
}
OpenAPI_change_type_e opVariable;
if (!cJSON_IsString(op)) {
ogs_error("OpenAPI_change_item_parseFromJSON() failed [op]");
goto end;
}
opVariable = OpenAPI_change_type_FromString(op->valuestring);
cJSON *path = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "path");
path = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "path");
if (!path) {
ogs_error("OpenAPI_change_item_parseFromJSON() failed [path]");
goto end;
}
if (!cJSON_IsString(path)) {
ogs_error("OpenAPI_change_item_parseFromJSON() failed [path]");
goto end;
}
cJSON *from = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "from");
from = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "from");
if (from) {
if (!cJSON_IsString(from)) {
if (!cJSON_IsString(from) && !cJSON_IsNull(from)) {
ogs_error("OpenAPI_change_item_parseFromJSON() failed [from]");
goto end;
}
}
cJSON *orig_value = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "origValue");
OpenAPI_any_type_t *orig_value_local_object = NULL;
orig_value = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "origValue");
if (orig_value) {
orig_value_local_object = OpenAPI_any_type_parseFromJSON(orig_value);
}
cJSON *new_value = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "newValue");
OpenAPI_any_type_t *new_value_local_object = NULL;
new_value = cJSON_GetObjectItemCaseSensitive(change_itemJSON, "newValue");
if (new_value) {
new_value_local_object = OpenAPI_any_type_parseFromJSON(new_value);
}
@ -147,13 +170,21 @@ OpenAPI_change_item_t *OpenAPI_change_item_parseFromJSON(cJSON *change_itemJSON)
change_item_local_var = OpenAPI_change_item_create (
opVariable,
ogs_strdup(path->valuestring),
from ? ogs_strdup(from->valuestring) : NULL,
from && !cJSON_IsNull(from) ? ogs_strdup(from->valuestring) : NULL,
orig_value ? orig_value_local_object : NULL,
new_value ? new_value_local_object : NULL
);
return change_item_local_var;
end:
if (orig_value_local_object) {
OpenAPI_any_type_free(orig_value_local_object);
orig_value_local_object = NULL;
}
if (new_value_local_object) {
OpenAPI_any_type_free(new_value_local_object);
new_value_local_object = NULL;
}
return NULL;
}