[WIP][DO NOT REVIEW YET] Replace YAJL with yyjson for JSON parsing and generation#2068
[WIP][DO NOT REVIEW YET] Replace YAJL with yyjson for JSON parsing and generation#2068giuseppe wants to merge 1 commit intocontainers:mainfrom
Conversation
|
Ephemeral COPR build failed. @containers/packit-build please check. |
There was a problem hiding this comment.
Code Review
This pull request replaces the YAJL JSON library with yyjson across the crun codebase, updating build scripts, submodules, and source files to use the new API. The migration includes transitioning from YAJL types and macros to yyjson's document and value structures for container management and feature reporting. Review feedback identifies critical safety issues, specifically potential segmentation faults in src/libcrun/status.c and src/libcrun/utils.c due to missing type and NULL checks when processing JSON strings. Additionally, it is recommended to use signed integer getters for pid_t to ensure proper type handling and range validation.
| if (UNLIKELY (tmp == NULL)) | ||
| return crun_make_error (err, 0, "`cgroup-path` missing in `%s`", file); | ||
| status->cgroup_path = xstrdup (YAJL_GET_STRING (tmp)); | ||
| status->cgroup_path = xstrdup (yyjson_get_str (tmp)); |
There was a problem hiding this comment.
The new implementation lacks type validation for the JSON value. yyjson_get_str(tmp) returns NULL if the value is not a string. Passing NULL to xstrdup will likely cause a segmentation fault. The previous YAJL implementation was safer as it explicitly checked for the string type during retrieval. You should verify the type before attempting to duplicate the string.
const char *val = yyjson_get_str (tmp);
if (UNLIKELY (val == NULL))
return crun_make_error (err, 0, "`cgroup-path` is not a string in `%s`", file);
status->cgroup_path = xstrdup (val);| if (UNLIKELY (tmp == NULL)) | ||
| return crun_make_error (err, 0, "`pid` missing in `%s`", file); | ||
| status->pid = strtoull (YAJL_GET_NUMBER (tmp), NULL, 10); | ||
| status->pid = (pid_t) yyjson_get_uint (tmp); |
There was a problem hiding this comment.
Using yyjson_get_uint to populate a pid_t (which is typically a signed integer) is slightly risky if the value could be negative or if it exceeds the range of pid_t. Additionally, the previous implementation using YAJL checked the type of the node. yyjson_obj_get followed by yyjson_get_uint will return 0 if the key exists but is not a number. Consider using yyjson_get_int and adding a type check to ensure robustness against malformed status files.
status->pid = (pid_t) yyjson_get_int (tmp);| *err = NULL; | ||
|
|
||
| *out = yajl_tree_parse (jsondata, errbuf, sizeof (errbuf)); | ||
| *out = yyjson_read (jsondata, strlen (jsondata), YYJSON_READ_NUMBER_AS_RAW); |
There was a problem hiding this comment.
Calling strlen on jsondata without checking if it is NULL will lead to a segmentation fault if the caller passes a null pointer. While the previous YAJL implementation might have handled this internally or via the caller, it is safer to add an explicit check here, especially since this is a utility function.
if (UNLIKELY (jsondata == NULL))
return crun_make_error (err, 0, "JSON data is NULL");
*out = yyjson_read (jsondata, strlen (jsondata), YYJSON_READ_NUMBER_AS_RAW);670bc40 to
d4b45d1
Compare
| - run: sudo apt-get update | ||
|
|
||
| - run: sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev | ||
| - run: sudo apt-get install -y make git gcc build-essential pkgconf libtool libsystemd-dev libcap-dev libseccomp-dev go-md2man libtool autoconf python3 automake libprotobuf-c-dev |
There was a problem hiding this comment.
(Sorry if this counts as a review 😛 )
Ubuntu actually ships yyjson (as libyyjson-dev) since 25.04, so ubuntu-latest should have it. Debian ships it since stable (trixie) as well. I see this removes libyajl-dev but does not add libyyjson-dev. Same for the other "apt-get" changes in test.yaml etc.
There was a problem hiding this comment.
thanks but they are not yet available in the versions used in the CI
656b123 to
8d7364e
Compare
Switch from the unmaintained YAJL library to yyjson for all JSON operations. Update the build system (configure.ac, Makefile.am) to use yyjson, and update the libocispec submodule to the version with yyjson support. gitmodules is pointing to my git repo for now. Needs: containers/libocispec#170 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Switch from the unmaintained YAJL library to yyjson for all JSON operations. Update the build system (configure.ac, Makefile.am) to use yyjson, and update the libocispec submodule to the version with yyjson support.
gitmodules is pointing to my git repo for now.
Needs: containers/libocispec#170