diff options
author | Björn Gustavsson <[email protected]> | 2011-09-02 13:27:41 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-09-03 08:29:21 +0200 |
commit | 12ebe3823b01be256b0834956bc2e117129b32e4 (patch) | |
tree | 2d61d77d8bbd4e3d97b06813590d41fb6bb25c58 /erts/test/erlc_SUITE.erl | |
parent | 9f1e455017228e8f35d82e2fe1e3c5268c2e0aa3 (diff) | |
download | otp-12ebe3823b01be256b0834956bc2e117129b32e4.tar.gz otp-12ebe3823b01be256b0834956bc2e117129b32e4.tar.bz2 otp-12ebe3823b01be256b0834956bc2e117129b32e4.zip |
erlc_SUITE: Fix arg_overflow/1 test case
In commit be8759e68b337524c056b8bb757ea68c9996d863, a buffer overflow
was fixed in erlc and the erlc_SUITE:arg_overflow/1 test case was
added. That test cases invokes erlc with 10000 -D options, which will
result in 'erl' being invoked with more than 30000 arguments.
On some platforms, the test case will fail for the wrong reason:
* 64-bit Linux kernels before 2.6.23 limit the number of arguments in
an excvp() call to 16383. (See "Number of arguments and maximum length
of one argument" in http://www.in-ulm.de/~mascheck/various/argmax/.)
* The command shell in Windows limits the size of the command line to
8191 characters.
Depending on the platform, pass a different number of -D options
to erlc. Since the size of the options does not matter for this
test case, make the options as short as possible by generating
numbers in base 36.
Diffstat (limited to 'erts/test/erlc_SUITE.erl')
-rw-r--r-- | erts/test/erlc_SUITE.erl | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/erts/test/erlc_SUITE.erl b/erts/test/erlc_SUITE.erl index 62e0e6813d..2b5cb11f02 100644 --- a/erts/test/erlc_SUITE.erl +++ b/erts/test/erlc_SUITE.erl @@ -213,13 +213,34 @@ deep_cwd_1(PrivDir) -> arg_overflow(Config) when is_list(Config) -> ?line {SrcDir, _OutDir, Cmd} = get_cmd(Config), ?line FileName = filename:join(SrcDir, "erl_test_ok.erl"), - ?line Args = lists:flatten([ ["-D", integer_to_list(N), "=1 "] || - N <- lists:seq(1,10000) ]), + %% Each -D option will be expanded to three arguments when + %% invoking 'erl'. + ?line NumDOptions = num_d_options(), + ?line Args = lists:flatten([ ["-D", integer_to_list(N, 36), "=1 "] || + N <- lists:seq(1, NumDOptions) ]), ?line run(Config, Cmd, FileName, Args, ["Warning: function foo/0 is unused\$", "_OK_"]), ok. +num_d_options() -> + case {os:type(),os:version()} of + {{win32,_},_} -> + %% The maximum size of a command line in the command + %% shell on Windows is 8191 characters. + %% Each -D option is expanded to "@dv NN 1", i.e. + %% 8 characters. (Numbers up to 1295 can be expressed + %% as two 36-base digits.) + 1000; + {{unix,linux},Version} when Version < {2,6,23} -> + %% On some older 64-bit versions of Linux, the maximum number + %% of arguments is 16383. + %% See: http://www.in-ulm.de/~mascheck/various/argmax/ + 5440; + {_,_} -> + 12000 + end. + erlc() -> case os:find_executable("erlc") of false -> |