[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

@ -24,19 +24,30 @@ OpenAPI_patch_item_t *OpenAPI_patch_item_create(
void OpenAPI_patch_item_free(OpenAPI_patch_item_t *patch_item)
{
OpenAPI_lnode_t *node = NULL;
if (NULL == patch_item) {
return;
}
OpenAPI_lnode_t *node;
ogs_free(patch_item->path);
ogs_free(patch_item->from);
OpenAPI_any_type_free(patch_item->value);
if (patch_item->path) {
ogs_free(patch_item->path);
patch_item->path = NULL;
}
if (patch_item->from) {
ogs_free(patch_item->from);
patch_item->from = NULL;
}
if (patch_item->value) {
OpenAPI_any_type_free(patch_item->value);
patch_item->value = NULL;
}
ogs_free(patch_item);
}
cJSON *OpenAPI_patch_item_convertToJSON(OpenAPI_patch_item_t *patch_item)
{
cJSON *item = NULL;
OpenAPI_lnode_t *node = NULL;
if (patch_item == NULL) {
ogs_error("OpenAPI_patch_item_convertToJSON() failed [PatchItem]");
@ -44,11 +55,19 @@ cJSON *OpenAPI_patch_item_convertToJSON(OpenAPI_patch_item_t *patch_item)
}
item = cJSON_CreateObject();
if (patch_item->op == OpenAPI_patch_operation_NULL) {
ogs_error("OpenAPI_patch_item_convertToJSON() failed [op]");
return NULL;
}
if (cJSON_AddStringToObject(item, "op", OpenAPI_patch_operation_ToString(patch_item->op)) == NULL) {
ogs_error("OpenAPI_patch_item_convertToJSON() failed [op]");
goto end;
}
if (!patch_item->path) {
ogs_error("OpenAPI_patch_item_convertToJSON() failed [path]");
return NULL;
}
if (cJSON_AddStringToObject(item, "path", patch_item->path) == NULL) {
ogs_error("OpenAPI_patch_item_convertToJSON() failed [path]");
goto end;
@ -81,42 +100,43 @@ end:
OpenAPI_patch_item_t *OpenAPI_patch_item_parseFromJSON(cJSON *patch_itemJSON)
{
OpenAPI_patch_item_t *patch_item_local_var = NULL;
cJSON *op = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "op");
OpenAPI_lnode_t *node = NULL;
cJSON *op = NULL;
OpenAPI_patch_operation_e opVariable = 0;
cJSON *path = NULL;
cJSON *from = NULL;
cJSON *value = NULL;
OpenAPI_any_type_t *value_local_object = NULL;
op = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "op");
if (!op) {
ogs_error("OpenAPI_patch_item_parseFromJSON() failed [op]");
goto end;
}
OpenAPI_patch_operation_e opVariable;
if (!cJSON_IsString(op)) {
ogs_error("OpenAPI_patch_item_parseFromJSON() failed [op]");
goto end;
}
opVariable = OpenAPI_patch_operation_FromString(op->valuestring);
cJSON *path = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "path");
path = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "path");
if (!path) {
ogs_error("OpenAPI_patch_item_parseFromJSON() failed [path]");
goto end;
}
if (!cJSON_IsString(path)) {
ogs_error("OpenAPI_patch_item_parseFromJSON() failed [path]");
goto end;
}
cJSON *from = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "from");
from = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "from");
if (from) {
if (!cJSON_IsString(from)) {
if (!cJSON_IsString(from) && !cJSON_IsNull(from)) {
ogs_error("OpenAPI_patch_item_parseFromJSON() failed [from]");
goto end;
}
}
cJSON *value = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "value");
OpenAPI_any_type_t *value_local_object = NULL;
value = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "value");
if (value) {
value_local_object = OpenAPI_any_type_parseFromJSON(value);
}
@ -124,12 +144,16 @@ OpenAPI_patch_item_t *OpenAPI_patch_item_parseFromJSON(cJSON *patch_itemJSON)
patch_item_local_var = OpenAPI_patch_item_create (
opVariable,
ogs_strdup(path->valuestring),
from ? ogs_strdup(from->valuestring) : NULL,
from && !cJSON_IsNull(from) ? ogs_strdup(from->valuestring) : NULL,
value ? value_local_object : NULL
);
return patch_item_local_var;
end:
if (value_local_object) {
OpenAPI_any_type_free(value_local_object);
value_local_object = NULL;
}
return NULL;
}