Skip to content

Conversation

@giuseppe
Copy link
Member

@giuseppe giuseppe commented Jan 7, 2026

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @giuseppe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the stability and robustness of the libcrun library by introducing several NULL pointer checks across various functions within src/libcrun/linux.c. These checks specifically target the linux configuration object and its related data structures, ensuring that they are valid before being accessed. This prevents potential segmentation faults and improves the overall reliability of the container runtime.

Highlights

  • NULL Pointer Checks in create_missing_devs: Added a check to ensure def->linux is not NULL before proceeding with operations in the create_missing_devs function, preventing potential crashes.
  • NULL Pointer Checks in do_masked_and_readonly_paths: Implemented a NULL check for def->linux at the beginning of the do_masked_and_readonly_paths function to safeguard against dereferencing a NULL pointer.
  • Improved NULL Safety for rootfs_propagation: Modified the condition in libcrun_set_mounts to explicitly check for a non-NULL def->linux before accessing its rootfs_propagation member.
  • NULL Pointer Checks in libcrun_set_usernamespace: Introduced a NULL check for def->linux in libcrun_set_usernamespace to ensure that subsequent accesses to its members are safe.
  • Enhanced NULL Checks in get_id_in_user_namespace: Added comprehensive NULL checks for def->linux and the mappings arrays (uid/gid) within get_id_in_user_namespace to prevent invalid memory access and improve robustness.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds several necessary NULL checks for the def->linux pointer before it is dereferenced, which prevents potential crashes. This is a good improvement. However, in several places, the def pointer itself is not checked for NULL before being used to access linux. If def can be NULL, this would still lead to a segmentation fault. I've pointed out these locations and suggested adding checks for def as well. I also found a minor opportunity to simplify one of the new checks by removing a redundant condition.

Comment on lines 1757 to 1758
if (! def->linux)
return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The def pointer, which is likely initialized from container->container_def, is dereferenced without a NULL check. If def is NULL, this will cause a segmentation fault. Please add a NULL check for def as well.

  if (!def || !def->linux)
    return 0;

Comment on lines 1845 to 1846
if (! def->linux)
return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The def pointer is dereferenced without being checked for NULL. If container->container_def is NULL, this will lead to a segmentation fault. You should add a NULL check for def.

  if (!def || !def->linux)
    return 0;

Comment on lines 3139 to 3140
if (! def->linux)
return 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The def pointer, initialized from container->container_def, is dereferenced without a NULL check. This could lead to a segmentation fault if container->container_def is NULL. Please add a check for def.

  if (!def || !def->linux)
    return 0;

Comment on lines 4378 to 4379
if (! def->linux)
goto exit;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The def pointer, passed as an argument, could be NULL. Dereferencing it to check def->linux would cause a segmentation fault. You should check def for NULL first.

  if (!def || !def->linux)
    goto exit;

Comment on lines 4384 to 4385
if (! mappings || len == 0)
goto exit;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The len == 0 check is redundant. The following for loop's condition (i < len) already handles the case where len is 0 by not executing the loop body. Removing this redundant check simplifies the code.

  if (!mappings)
    goto exit;

@packit-as-a-service
Copy link

TMT tests failed. @containers/packit-build please check.

@giuseppe
Copy link
Member Author

giuseppe commented Jan 8, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds several NULL pointer checks before accessing members of the def and def->linux structs. These changes improve the robustness of the code by preventing potential segmentation faults. The added checks in create_missing_devs, do_masked_and_readonly_paths, libcrun_set_mounts, libcrun_set_usernamespace, and get_id_in_user_namespace are correct and necessary. I have one suggestion for a minor code simplification.

Comment on lines 4384 to 4385
if (! mappings || len == 0)
goto exit;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check for len == 0 is redundant. If len is 0, the subsequent for loop for (i = 0; i < len; i++) will not execute its body, and the function will proceed to the exit: label, which has the same effect as goto exit;. You can simplify the condition to only check if mappings is NULL.

  if (! mappings)
    goto exit;

Signed-off-by: Giuseppe Scrivano <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant