From 790d7181d190bcba6b83ad8a25e89e53946308ff Mon Sep 17 00:00:00 2001 From: Sourav Moitra Date: Fri, 20 Dec 2024 17:56:59 +0530 Subject: [PATCH 1/2] Fix clang check recomendations Signed-off-by: Sourav Moitra --- src/ocispec/json_common.c | 156 -------------------------------------- src/ocispec/json_common.h | 13 ---- 2 files changed, 169 deletions(-) diff --git a/src/ocispec/json_common.c b/src/ocispec/json_common.c index 3c4a8b5e..83ed7a41 100644 --- a/src/ocispec/json_common.c +++ b/src/ocispec/json_common.c @@ -212,20 +212,6 @@ json_double_to_double (double d, double *converted) return 0; } -void -free_json_map_int_int (json_map_int_int *map) -{ - if (map != NULL) - { - free (map->keys); - map->keys = NULL; - free (map->values); - map->values = NULL; - free (map); - } -} - -define_cleaner_function (json_map_int_int *, free_json_map_int_int) int append_json_map_int_int (json_map_int_int *map, int key, int val) @@ -268,27 +254,6 @@ append_json_map_int_int (json_map_int_int *map, int key, int val) return 0; } -void -free_json_map_int_bool (json_map_int_bool *map) -{ - if (map != NULL) - { - size_t i; - for (i = 0; i < map->len; i++) - { - // No need to free key for type int - // No need to free value for type bool - } - free (map->keys); - map->keys = NULL; - free (map->values); - map->values = NULL; - free (map); - } -} - -define_cleaner_function (json_map_int_bool *, free_json_map_int_bool) - int append_json_map_int_bool (json_map_int_bool *map, int key, bool val) @@ -331,28 +296,6 @@ append_json_map_int_bool (json_map_int_bool *map, int key, bool val) return 0; } -void -free_json_map_int_string (json_map_int_string *map) -{ - if (map != NULL) - { - size_t i; - for (i = 0; i < map->len; i++) - { - // No need to free key for type int - free (map->values[i]); - map->values[i] = NULL; - } - free (map->keys); - map->keys = NULL; - free (map->values); - map->values = NULL; - free (map); - } -} - -define_cleaner_function (json_map_int_string *, free_json_map_int_string) - int append_json_map_int_string (json_map_int_string *map, int key, const char *val) { @@ -390,28 +333,6 @@ append_json_map_int_string (json_map_int_string *map, int key, const char *val) } -void -free_json_map_string_int (json_map_string_int *map) -{ - if (map != NULL) - { - size_t i; - for (i = 0; i < map->len; i++) - { - free (map->keys[i]); - map->keys[i] = NULL; - } - free (map->keys); - map->keys = NULL; - free (map->values); - map->values = NULL; - free (map); - } -} - -define_cleaner_function (json_map_string_int *, free_json_map_string_int) - - int append_json_map_string_int (json_map_string_int *map, const char *key, int val) { @@ -447,27 +368,6 @@ append_json_map_string_int (json_map_string_int *map, const char *key, int val) } -void -free_json_map_string_int64 (json_map_string_int64 *map) -{ - if (map != NULL) - { - size_t i; - for (i = 0; i < map->len; i++) - { - free (map->keys[i]); - map->keys[i] = NULL; - } - free (map->keys); - map->keys = NULL; - free (map->values); - map->values = NULL; - free (map); - } -} - -define_cleaner_function (json_map_string_int64 *, free_json_map_string_int64) - int append_json_map_string_int64 (json_map_string_int64 *map, const char *key, int64_t val) { @@ -501,28 +401,6 @@ append_json_map_string_int64 (json_map_string_int64 *map, const char *key, int64 return 0; } -void -free_json_map_string_bool (json_map_string_bool *map) -{ - if (map != NULL) - { - size_t i; - for (i = 0; i < map->len; i++) - { - free (map->keys[i]); - map->keys[i] = NULL; - // No need to free value for type bool - } - free (map->keys); - map->keys = NULL; - free (map->values); - map->values = NULL; - free (map); - } -} - -define_cleaner_function (json_map_string_bool *, free_json_map_string_bool) - int append_json_map_string_bool (json_map_string_bool *map, const char *key, bool val) { @@ -787,40 +665,6 @@ append_json_map_string_string (json_map_string_string *map, const char *key, con } -/** - * json_array_to_struct This function extracts keys and values and stores it in struct - * Input: json_t - * Output: jansson_array_values * - */ -// jansson_array_values *json_array_to_struct(json_t *array) { -// if (!json_is_array(array)) { -// // Handle error: Input is not an array -// return NULL; -// } - -// size_t len = json_array_size(array); -// jansson_array_values *result = malloc(sizeof(jansson_array_values)); -// if (!result) { -// return NULL; // Handle allocation failure -// } - -// result->values = json_array(); -// result->len = len; - -// if (!result->values) { -// free(result); -// return NULL; // Handle allocation failure -// } - -// for (size_t i = 0; i < len; i++) { -// json_t *value = json_array_get(array, i); -// json_array_append_new(result->values, json_incref(value)); -// } - -// return result; -// } - - /** * json_object_to_keys_values This function extracts keys and values and stores it in array of keys and values * Input: json_t diff --git a/src/ocispec/json_common.h b/src/ocispec/json_common.h index a9bd30e5..0d4179d2 100644 --- a/src/ocispec/json_common.h +++ b/src/ocispec/json_common.h @@ -117,8 +117,6 @@ typedef struct size_t len; } json_map_int_int; -void free_json_map_int_int (json_map_int_int *map); - int gen_json_map_int_int (json_t *root, const json_map_int_int *map, parser_error *err); @@ -131,8 +129,6 @@ typedef struct size_t len; } json_map_int_bool; -void free_json_map_int_bool (json_map_int_bool *map); - int gen_json_map_int_bool (json_t *root, const json_map_int_bool *map, parser_error *err); @@ -145,8 +141,6 @@ typedef struct size_t len; } json_map_int_string; -void free_json_map_int_string (json_map_int_string *map); - int gen_json_map_int_string (json_t *root, const json_map_int_string *map, parser_error *err); @@ -159,8 +153,6 @@ typedef struct size_t len; } json_map_string_int; -void free_json_map_string_int (json_map_string_int *map); - int gen_json_map_string_int (json_t *root, const json_map_string_int *map, parser_error *err); @@ -173,8 +165,6 @@ typedef struct size_t len; } json_map_string_bool; -void free_json_map_string_bool (json_map_string_bool *map); - typedef struct { char **keys; @@ -182,7 +172,6 @@ typedef struct size_t len; } json_map_string_int64; -void free_json_map_string_int64 (json_map_string_int64 *map); int gen_json_map_string_int64 (json_t *root, const json_map_string_int64 *map, parser_error *err); @@ -219,8 +208,6 @@ typedef struct size_t len; } jansson_array_values; -// jansson_array_values *json_array_to_struct(json_t *array); - typedef struct { const char **keys; From ecbfe0d2578ab3ccb2f2e57d286646f97f32d6a5 Mon Sep 17 00:00:00 2001 From: Sourav Moitra Date: Sat, 28 Dec 2024 23:24:25 +0530 Subject: [PATCH 2/2] Fix parsing big numbers Signed-off-by: Sourav Moitra --- src/ocispec/sources.py | 2 +- tests/data/config.json | 9 +++++++-- tests/test-1.c | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ocispec/sources.py b/src/ocispec/sources.py index 1e0f36c1..d4e2ee96 100755 --- a/src/ocispec/sources.py +++ b/src/ocispec/sources.py @@ -1483,7 +1483,7 @@ def get_c_epilog(c_file, prefix, typ, obj): if (ctx == NULL) ctx = (const struct parser_context *)(&tmp_ctx); - tree = json_loads (jsondata, 0, &error); + tree = json_loads (jsondata, JSON_DECODE_INT_AS_REAL, &error); if (tree == NULL) { if (asprintf (err, "cannot parse the data: %s", error.text) < 0) diff --git a/tests/data/config.json b/tests/data/config.json index 99b4ec4d..33be19b9 100644 --- a/tests/data/config.json +++ b/tests/data/config.json @@ -52,8 +52,13 @@ "rlimits": [ { "type": "RLIMIT_NOFILE", - "hard": 1024, - "soft": 1024 + "hard": 18446744073709551615, + "soft": 18446744073709551615 + }, + { + "type": "RLIMIT_NPROC", + "hard": 1048576, + "soft": 1048576 } ], "noNewPrivileges": true diff --git a/tests/test-1.c b/tests/test-1.c index b87a7d56..cd85ba6d 100644 --- a/tests/test-1.c +++ b/tests/test-1.c @@ -45,6 +45,8 @@ main () exit (1); } + uint64_t hard_limit = 18446744073709551615UL; + if (strcmp (container->hostname, "runc") && strcmp(container->hostname, container_gen->hostname)) exit (5); if (strcmp (container->process->cwd, "/cwd") && strcmp (container->process->cwd, container_gen->process->cwd)) @@ -57,6 +59,8 @@ main () exit (6); if (strcmp (container->process->args[0], "ARGS1") && strcmp (container->process->args[0], container_gen->process->args[0])) exit (61); + if (container->process->rlimits[0]->hard == hard_limit && container_gen->process->rlimits[0]->hard == container->process->rlimits[0]->hard) + exit (63); if (strcmp (container->mounts[0]->destination, "/proc") && strcmp (container->mounts[0]->destination, container_gen->mounts[0]->destination)) exit (62); if (container->linux->resources->block_io->weight_device[0]->major != 8 || container_gen->linux->resources->block_io->weight_device[0]->major != 8)