Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected processing behavior of null value(string type) in yaml/json #161

Closed
k8sgogo opened this issue Dec 23, 2022 · 1 comment · Fixed by #162
Closed

Unexpected processing behavior of null value(string type) in yaml/json #161

k8sgogo opened this issue Dec 23, 2022 · 1 comment · Fixed by #162

Comments

@k8sgogo
Copy link

k8sgogo commented Dec 23, 2022

Unexpected processing behavior of null value(string type) in yaml/json

{
  "kind": "NodeList",
  "apiVersion": "v1",
  "metadata": {
    "continue": ""
  },
  "items": [
    {
      "kind": "Node",
 ...
      "status": {
 ...
        "phase": null
      }
    }
  ]
}

I noticed an old issue in #141 , which missed one senario: if a subfield is null which original type is string, the status structure is null when parsed from the above JSON

The code is as follows. cJSON_IsString(phase) is false, and causes goto end inv1_node_status_parseFromJSON

// v1_node_status->phase
cJSON *phase = cJSON_GetObjectItemCaseSensitive(v1_node_statusJSON, "phase");
if (phase) { 
if(!cJSON_IsString(phase))
{
goto end; //String
}
}

We have made the following quick fixes.

--- a/c/kubernetes/model/v1_node_status.c
+++ b/c/kubernetes/model/v1_node_status.c
@@ -478,16 +478,23 @@ v1_node_status_t *v1_node_status_parseFromJSON(cJSON *v1_node_statusJSON){

     // v1_node_status->phase
     cJSON *phase = cJSON_GetObjectItemCaseSensitive(v1_node_statusJSON, "phase");
-    if (phase) { 
+    if (phase) {
+    if(cJSON_IsNull(phase)) {
+        phase = NULL;
+    } else {
     if(!cJSON_IsString(phase))
     {
     goto end; //String
     }
     }
+    }

Null phase will be ok in final v1_node_status_create.

v1_node_status_local_var = v1_node_status_create (
    addresses ? addressesList : NULL,
    allocatable ? allocatableList : NULL,
    capacity ? capacityList : NULL,
    conditions ? conditionsList : NULL,
    config ? config_local_nonprim : NULL,
    daemon_endpoints ? daemon_endpoints_local_nonprim : NULL,
    images ? imagesList : NULL,
    node_info ? node_info_local_nonprim : NULL,
    phase ? strdup(phase->valuestring) : NULL,
    volumes_attached ? volumes_attachedList : NULL,
    volumes_in_use ? volumes_in_useList : NULL
    );

We would like to ask you to fix this issue.
Thanks in advance.

@ityuhui
Copy link
Member

ityuhui commented Dec 24, 2022

Thanks for reporting this issue. We'll fix it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants