c icon indicating copy to clipboard operation
c copied to clipboard

events_v1_event_parseFromJSON SegFault due to invalid cJSON pointer

Open caesar0301 opened this issue 1 year ago • 2 comments

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

https://github.com/kubernetes-client/c/blob/2d93989a21591b0748485dd0919d713e0121db22/kubernetes/model/events_v1_event.c#L465

caesar0301 avatar Aug 19 '24 08:08 caesar0301

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,

caesar0301 avatar Aug 19 '24 09:08 caesar0301

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.

ityuhui avatar Aug 20 '24 08:08 ityuhui

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-triage-robot avatar Nov 18 '24 09:11 k8s-triage-robot

The Kubernetes project currently lacks enough active 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 rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

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

/lifecycle rotten

k8s-triage-robot avatar Dec 18 '24 10:12 k8s-triage-robot

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

This bot triages 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:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

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

/close not-planned

k8s-triage-robot avatar Jan 17 '25 10:01 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

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

This bot triages 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:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

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

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Jan 17 '25 10:01 k8s-ci-robot