From 12ebe3823b01be256b0834956bc2e117129b32e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 2 Sep 2011 13:27:41 +0200 Subject: 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. --- erts/test/erlc_SUITE.erl | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'erts/test') 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 -> -- cgit v1.2.3