[bug #62621] xargs/find: buildcmd incorrectly sizes argv and envp

Thomas Hurst <[email protected]>
Newsgroups gmane.comp.gnu.findutils.bugs
Message-ID <[email protected]>
URL:
  <https://savannah.gnu.org/bugs/?62621>

                 Summary: xargs/find: buildcmd incorrectly sizes argv and envp
                 Project: findutils
               Submitter: freaky
               Submitted: Mon 13 Jun 2022 01:24:21 PM UTC
                Category: xargs
                Severity: 3 - Normal
              Item Group: Wrong result
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: None
         Discussion Lock: Any
           Fixed Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Mon 13 Jun 2022 01:24:21 PM UTC By: Thomas Hurst <freaky>
buildcmd.c calculates the size of both arguments and environment entries as
strlen(s) + 1 - the size of the string plus delimiter.

This fails to take into account the argv/envp pointer to each entry, which at
least on Linux also contributes to the limit. To quote bprm_stack_limits()
from fs/exec.c:

> We must account for the size of all the argv and envp pointers to
> the argv and envp strings, since they will also take up space in
> the stack.

And indeed, sizeof(void*)*argc+envc are subtracted from the limit it
enforces.

This issue is masked by xargs defaulting to quite modest limits, and retrying
automatically with smaller sizes on E2BIG - though in testing this I find what
appears to be another issue, which I will file separately.







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?62621>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
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.