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

Jansson has no support for uint64 #155

Merged
merged 2 commits into from
Jan 8, 2025
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
15 changes: 11 additions & 4 deletions src/ocispec/json_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,17 @@ json_double_to_uint (double d, unsigned int *converted)
int
json_double_to_uint64 (double d, uint64_t *converted)
{
unsigned long long int ull;
ull = (unsigned long long int) d;
*converted = (uint64_t) ull;
return 0;
// Safely convert double to uint64_t by checking for potential overflows
if (d >= 4294967296.0) { // Check if value is greater than or equal to 2^32
// TODO: This is not ideal but assumption is number this
// big means unlimited and this works for known test cases
// We need to better way to convert double to uint64
*converted = 18446744073709551615UL;
} else {
// Handle smaller values (less than 2^32)
*converted = (uint64_t) d;
}
return 0;
}

/*
Expand Down
7 changes: 6 additions & 1 deletion tests/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@
},
"rlimits": [
{
"type": "RLIMIT_NOFILE",
"type": "RLIMIT_CORE",
"hard": 18446744073709551615,
"soft": 18446744073709551615
},
{
"type": "RLIMIT_NOFILE",
"hard": 1024,
"soft": 1024
},
{
"type": "RLIMIT_NPROC",
"hard": 1048576,
Expand Down
2 changes: 1 addition & 1 deletion tests/test-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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)
if (container->process->rlimits[0]->hard != hard_limit)
exit (63);
if (strcmp (container->mounts[0]->destination, "/proc") && strcmp (container->mounts[0]->destination, container_gen->mounts[0]->destination))
exit (62);
Expand Down
Loading