Bug 54

Summary: Argument list too long errors
Product: Sudo Reporter: steve
Component: SudoAssignee: Todd C. Miller <Todd.Miller>
Status: RESOLVED FIXED    
Severity: low    
Priority: normal    
Version: 1.6.3   
Hardware: PC   
OS: OpenBSD   

Description steve 2001-10-27 14:09:30 MDT
"Argument list too long" error messages:

I am developing an application in Python which does a system call to sudo to
allow it to list files in directories. Some directories have almost 10,000
files in them. '*' expands this with paths creating a huge string. Yes, this
does seem insanely large, but the point is that 'sh' will process this string
fine and 'sudo' will not. It seems to me ideally 'sudo' would have the same
limit that 'sh' has.

"It's not a bug, it's a feature!"
Comment 1 Todd C. Miller 2001-10-28 21:51:59 MST
Sudo does not have an arbitrary limit on the length of command line arguments.  This error is most likely coming from the kernel (execvp is returning E2BIG) before sudo is even run.  I suspect if you run the ls w/o sudo and are careful to make sure /bin/ls is being run and not a shell builtin you will get the same behavior.  I use tcsh, which has a builtin ls.  I was able to do an ls of all my mail messages in all folders using the tcsh builtin ls but doing "sudo ls Mail/*/*" or /bin/ls Mail/*/*" yielded the dreaded "Argument list too long".

The kernel does impose a limit to the size of the arguments passed to the exec() family of functions (ARG_MAX, 256KB on OpenBSD) and that is what you are running up against.  The workaround is to use xargs(1).