2

I would like to know what is the maximum size of the list of arguments in C/C++ main function? Does it depend on the OS? And what happens if I pass the very large number of arguments to the main function, the main function behavior will be indetermined?

Thanks,

  • I mean how many we can pass and is it a security issue if I pass the number of arguments bigger than the maximun size? – channgo2203 Apr 17 '15 at 09:33
  • 1
    check this [SO post](http://stackoverflow.com/questions/14419464/c-argv-what-is-the-maximum-size-of-data) for a theoretical discussion of argument sizes. what context requires this knowledge ? – amdixon Apr 17 '15 at 09:34
  • 1
    @channgo2203 I think Linux restricts the size of the argument vector to 128 kB. Generally, if you try to start a program with more arguments, the call to `exec` fails. – fuz Apr 17 '15 at 09:35
  • thanks FUZxxl, however, in the main(int argc, char* argv) if I pass to argc the very large number and the list of strings to argv such that they are smaller than 128KB, what happens, maybe exec fails, I will check it. – channgo2203 Apr 17 '15 at 09:40
  • @channgo2203 Why should anything strange happen in such a case? The array of pointers `argv` counts towards the 128 kB; you won't get any problem. – fuz Apr 17 '15 at 09:56

1 Answers1

2

Yes, it depends on OS, but the limitation is about number of characters that can be passed to a process rather than the number of arguments. See this: Maximum Length of Command Line String

Community
  • 1
  • 1
rubix_addict
  • 1,811
  • 13
  • 27
  • thanks rubix_addict, is there secuirty issue if the number of characters is large and the strings are ill-formed? – channgo2203 Apr 17 '15 at 09:42