Re: [PATCH] Improve execl* functions

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Hi Federico,

On Jan 26 12:14, Federico Terraneo wrote:
> Hi,
> I propose the following patch to the execl* functions in newlib that does
> the following:
> - it returns an error if more than the maximum number of arguments are
> passed instead of corrupting the stack
> - it allows to tweak the maximum number of arguments at the time of
> compiling newlib by defining the ARG_NUM_MAX macro
> 
> This patch is originally meant for the Miosix OS to allow reducing the
> maximum number of arguments with the intent of reducing the stack usage of
> the execl* functions in low memory microcontrollers, but I think it is of
> general applicability and can of course be useful also to increase this
> value for desktop-class targets.
> 
> Best regards,
> Federico Terraneo
> 
> 

I'm sorry, but I don't think this is the right thing to do.  Actually,
not even for Miosix OS.  Here's why:

Adding ARG_NUM_MAX this way requires all targets to define their own
ARG_NUM_MAX if they want to support more than 256 args.  Right now,
there's no such limitation.

There already is a standarized way for all targets to tell userspace how
much memory can be used by the exec(3) family of functions:

  ARG_MAX from limits.h or sysconf (_SC_ARG_MAX) from unistd.h

  must be >= _POSIX_ARG_MAX (4096)

ARG_MAX does not define a max number of args.  It defines a max number
of bytes used for arguments and environment combined.  This is what
should be tested for in exec(3), if you want to enforce memory usage
restrictions.


Thanks,
Corinna
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.