Skip to contentSkip to conversation

kernelshark: Fix TEP filter array parsing logic

PATCH In review Ciunas Bennett 3 participants 3 messages Feb 24 – Feb 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernelshark: Fix TEP filter array parsing logic

When saving a session with more than a single TEP advanced filter, KernelShark triggers a json-c assertion:

"json_object_array_get_idx: Assertion `json_object_get_type(jso) == json_type_array' failed."

This is caused because the code reuses the jfilter variable inside the loop to fetch each array element:

    jfilter = json_object_array_get_idx(jfilter, i);

This overwrites the original array object. On the next iteration, jfilter is no longer a json_type_array, causing the assertion.

Fix this by introducing a temporary variable jitem to store each array element, leaving jfilter to point to the actual array.

---
 src/libkshark-configio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/libkshark-configio.c +4 -4
index 88c2c9a..568ec73 100644
@@ -1528,7 +1528,7 @@ bool kshark_export_adv_filters(struct kshark_context *kshark_ctx, int sd,
 static bool kshark_adv_filters_from_json(struct kshark_data_stream *stream,
 					 struct json_object *jobj)
 {
-	json_object *jfilter, *jname, *jcond;
+	json_object *jfilter, *jname, *jcond, *jitem;
 	int i, length, n, ret = 0;
 	char *filter_str = NULL;
 
@@ -1548,10 +1548,10 @@ static bool kshark_adv_filters_from_json(struct kshark_data_stream *stream,
 	/* Set the filter. */
 	length = json_object_array_length(jfilter);
 	for (i = 0; i < length; ++i) {
-		jfilter = json_object_array_get_idx(jfilter, i);
+		jitem = json_object_array_get_idx(jfilter, i);
 
-		if (!json_object_object_get_ex(jfilter, "name", &jname) ||
-		    !json_object_object_get_ex(jfilter, "condition", &jcond))
+		if (!json_object_object_get_ex(jitem, "name", &jname) ||
+		    !json_object_object_get_ex(jitem, "condition", &jcond))
 			goto fail;
 
 		n = asprintf(&filter_str, "%s:%s",
Signature · 1 line
2.53.0
#1 lore raw

On Tue, 24 Feb 2026 17:05:25 +0000
Ciunas Bennett <[email protected]> wrote:

Thanks, I'm adding Yordan to the Cc as he's maintaining KernelShark.

-- Steve

Quoted 49 lines

When saving a session with more than a single TEP advanced filter, KernelShark triggers a json-c assertion:

"json_object_array_get_idx: Assertion `json_object_get_type(jso) == json_type_array' failed."

This is caused because the code reuses the jfilter variable inside the loop to fetch each array element:

    jfilter = json_object_array_get_idx(jfilter, i);

This overwrites the original array object. On the next iteration, jfilter is no longer a json_type_array, causing the assertion.

Fix this by introducing a temporary variable jitem to store each array element, leaving jfilter to point to the actual array.

---
 src/libkshark-configio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/libkshark-configio.c +4 -4
index 88c2c9a..568ec73 100644
@@ -1528,7 +1528,7 @@ bool kshark_export_adv_filters(struct kshark_context *kshark_ctx, int sd,
 static bool kshark_adv_filters_from_json(struct kshark_data_stream *stream,
 					 struct json_object *jobj)
 {
-	json_object *jfilter, *jname, *jcond;
+	json_object *jfilter, *jname, *jcond, *jitem;
 	int i, length, n, ret = 0;
 	char *filter_str = NULL;
 
@@ -1548,10 +1548,10 @@ static bool kshark_adv_filters_from_json(struct kshark_data_stream *stream,
 	/* Set the filter. */
 	length = json_object_array_length(jfilter);
 	for (i = 0; i < length; ++i) {
-		jfilter = json_object_array_get_idx(jfilter, i);
+		jitem = json_object_array_get_idx(jfilter, i);
 
-		if (!json_object_object_get_ex(jfilter, "name", &jname) ||
-		    !json_object_object_get_ex(jfilter, "condition", &jcond))
+		if (!json_object_object_get_ex(jitem, "name", &jname) ||
+		    !json_object_object_get_ex(jitem, "condition", &jcond))
 			goto fail;
 
 		n = asprintf(&filter_str, "%s:%s",
#2 lore raw
In reply to Ciunas Bennett

The patch is applied. Thanks!

Yordan

Quoted 49 lines · Ciunas Bennett

When saving a session with more than a single TEP advanced filter, KernelShark triggers a json-c assertion:

"json_object_array_get_idx: Assertion `json_object_get_type(jso) == json_type_array' failed."

This is caused because the code reuses the jfilter variable inside the loop to fetch each array element:

     jfilter = json_object_array_get_idx(jfilter, i);

This overwrites the original array object. On the next iteration, jfilter is no longer a json_type_array, causing the assertion.

Fix this by introducing a temporary variable jitem to store each array element, leaving jfilter to point to the actual array.

---
  src/libkshark-configio.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
src/libkshark-configio.c +4 -4
index 88c2c9a..568ec73 100644
@@ -1528,7 +1528,7 @@ bool kshark_export_adv_filters(struct kshark_context *kshark_ctx, int sd,
  static bool kshark_adv_filters_from_json(struct kshark_data_stream *stream,
  					 struct json_object *jobj)
  {
-	json_object *jfilter, *jname, *jcond;
+	json_object *jfilter, *jname, *jcond, *jitem;
  	int i, length, n, ret = 0;
  	char *filter_str = NULL;
 
@@ -1548,10 +1548,10 @@ static bool kshark_adv_filters_from_json(struct kshark_data_stream *stream,
  	/* Set the filter. */
  	length = json_object_array_length(jfilter);
  	for (i = 0; i < length; ++i) {
-		jfilter = json_object_array_get_idx(jfilter, i);
+		jitem = json_object_array_get_idx(jfilter, i);
 
-		if (!json_object_object_get_ex(jfilter, "name", &jname) ||
-		    !json_object_object_get_ex(jfilter, "condition", &jcond))
+		if (!json_object_object_get_ex(jitem, "name", &jname) ||
+		    !json_object_object_get_ex(jitem, "condition", &jcond))
  			goto fail;
 
  		n = asprintf(&filter_str, "%s:%s",