Re: [PATCH] nproc: Verify the cgroup path isn't truncated.

Pádraig Brady <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
On 16/08/2026 07:50, Collin Funk wrote:
> I don't think it is actually possible for this case to happen, but
> checking it does no harm.
> 
> Lasse Collin mentioned it to me while we were discussing some cgroup
> stuff a while ago.
> 

> diff --git a/lib/nproc.c b/lib/nproc.c
> index ef86975fb1..e3dfeaa16d 100644
> --- a/lib/nproc.c
> +++ b/lib/nproc.c
> @@ -437,10 +437,11 @@ get_cgroup2_cpu_quota (void)
>            is not enabled for that part of the hierarchy.  */
>   
>         char cpu_max_file[PATH_MAX];
> -      snprintf (cpu_max_file, sizeof (cpu_max_file),
> -                "%s%s/cpu.max", mount, cgroup);
> +      int n = snprintf (cpu_max_file, sizeof (cpu_max_file),
> +                        "%s%s/cpu.max", mount, cgroup);
>   
> -      if ((fp = fopen (cpu_max_file, "r"))
> +      if (0 <= n && n < sizeof cpu_max_file
> +          && (fp = fopen (cpu_max_file, "r"))
>             && getline (&quota_str, &quota_size, fp) != -1
>             && strncmp (quota_str, "max", 3) != 0)
>           {

LGTM.

cheers,
Padraig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.