bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pgrep and pkill (any? arguments): cannot allocate 4294967295 bytes


From: Samuel Thibault
Subject: Re: pgrep and pkill (any? arguments): cannot allocate 4294967295 bytes
Date: Tue, 2 Feb 2021 18:36:16 +0100
User-agent: NeoMutt/20170609 (1.8.3)

Paul Dufresne, le mar. 02 févr. 2021 12:30:25 -0500, a ecrit:
> I think it is cleaner like this:
> 
> root@kibar:~/procps-3.3.16# diff -u ../orig/procps-3.3.16/pgrep.c pgrep.c
> --- ../orig/procps-3.3.16/pgrep.c       2020-02-06 06:04:02.000000000 -0500
> +++ pgrep.c     2021-02-02 12:24:49.000000000 -0500
> @@ -494,10 +494,15 @@
>         pid_t saved_pid = 0;                      /* for new/old support */
>         int matches = 0;
>         int size = 0;
> +       long cmdlen, SC_ARG_MAX;

Better not use an upper case for a variable name, that's normally only
for macros.

>         regex_t *preg;
>         pid_t myself = getpid();
>         struct el *list = NULL;
> -        long cmdlen = sysconf(_SC_ARG_MAX) * sizeof(char);
> +       SC_ARG_MAX = sysconf(_SC_ARG_MAX);
> +       if (SC_ARG_MAX == -1) // no limitations
> +               cmdlen = 1000 * sizeof(char);
> +       else
> +               cmdlen = SC_ARG_MAX * sizeof(char);
>         char *cmdline = xmalloc(cmdlen);
>         char *cmdsearch = xmalloc(cmdlen);
>         char *cmdoutput = xmalloc(cmdlen);

Probably they will prefer to avoid the if/else within the variable
declarations, i.e. move the if/else and the xmalloc after the variable
declarations.

Also, 1000 is a random value, it'd probably be preferrable to use
_POSIX_ARG_MAX (the default posix minimum). And probably the code using
cmdline, cmdsearch and cmdoutput need to watch out for this size.

Samuel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]