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

events_v1_event_parseFromJSON SegFault due to invalid cJSON pointer #245

Open
caesar0301 opened this issue Aug 19, 2024 · 3 comments
Open
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@caesar0301
Copy link
Contributor

This segfault occurs due to a lack of valid cJSON obj validation in events_v1_event_parseFromJSON

strdup(event_time->valuestring),

@caesar0301
Copy link
Contributor Author

I got events with null event_time from my k8s cluster (v1.22). For stability purpose, we should make the object <-> JSON conversion smooth. Here is my proposed improvement:

diff --git a/client/kubernetes/model/events_v1_event.c b/client/kubernetes/model/events_v1_event.c
index 59a4e2d..70cd75e 100644
--- a/client/kubernetes/model/events_v1_event.c
+++ b/client/kubernetes/model/events_v1_event.c
@@ -179,12 +179,11 @@ cJSON *events_v1_event_convertToJSON(events_v1_event_t *events_v1_event) {
 
 
     // events_v1_event->event_time
-    if (!events_v1_event->event_time) {
-        goto fail;
-    }
+    if (events_v1_event->event_time) {
     if(cJSON_AddStringToObject(item, "eventTime", events_v1_event->event_time) == NULL) {
     goto fail; //Date-Time
     }
+    }
 
 
     // events_v1_event->kind
@@ -462,7 +461,7 @@ events_v1_event_t *events_v1_event_parseFromJSON(cJSON *events_v1_eventJSON){
         deprecated_first_timestamp && !cJSON_IsNull(deprecated_first_timestamp) ? strdup(deprecated_first_timestamp->valuestring) : NULL,
         deprecated_last_timestamp && !cJSON_IsNull(deprecated_last_timestamp) ? strdup(deprecated_last_timestamp->valuestring) : NULL,
         deprecated_source ? deprecated_source_local_nonprim : NULL,
-        strdup(event_time->valuestring),
+        event_time && !cJSON_IsNull(event_time) ? strdup(event_time->valuestring) : NULL,
         kind && !cJSON_IsNull(kind) ? strdup(kind->valuestring) : NULL,
         metadata ? metadata_local_nonprim : NULL,
         note && !cJSON_IsNull(note) ? strdup(note->valuestring) : NULL,

@ityuhui
Copy link
Member

ityuhui commented Aug 20, 2024

event_time is required by K8S API spec https://raw.githubusercontent.com/kubernetes-client/c/master/kubernetes/swagger.json. So it should not be NULL

By comparison, deprecatedLastTimestamp is optional.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

4 participants