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

uint4 parsing fix #154

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 0 additions & 156 deletions src/ocispec/json_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions src/ocispec/json_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -173,16 +165,13 @@ typedef struct
size_t len;
} json_map_string_bool;

void free_json_map_string_bool (json_map_string_bool *map);

typedef struct
{
char **keys;
int64_t *values;
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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ocispec/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions tests/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/test-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
Loading