commit:     a308d831ceb1f1e7d0733700117cc18c8eca09c8
Author:     Matoro Mahri <matoro_gentoo <AT> matoro <DOT> tk>
AuthorDate: Wed Jan 31 20:26:06 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb  9 07:08:22 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a308d831

tests: process: calculate size of E2BIG environment variable dynamically

The size of the command line required to trigger E2BIG response from the
kernel is defined as MAX_ARG_STRLEN, which is equal to 32 * PAGE_SIZE.
Therefore the minimum size required to trigger the expected error
response must be calculated dynamically based on PAGE_SIZE.

Bug: https://bugs.gentoo.org/923368
Signed-off-by: Matoro Mahri <matoro_gentoo <AT> matoro.tk>
Closes: https://github.com/gentoo/portage/pull/1246
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/process/test_spawn_fail_e2big.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/portage/tests/process/test_spawn_fail_e2big.py 
b/lib/portage/tests/process/test_spawn_fail_e2big.py
index 7a00966302..abb1113fea 100644
--- a/lib/portage/tests/process/test_spawn_fail_e2big.py
+++ b/lib/portage/tests/process/test_spawn_fail_e2big.py
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import platform
+import resource
 
 import pytest
 
@@ -12,7 +13,9 @@ from portage.const import BASH_BINARY
 @pytest.mark.skipif(platform.system() != "Linux", reason="not Linux")
 def test_spawnE2big(capsys, tmp_path):
     env = dict()
-    env["VERY_LARGE_ENV_VAR"] = "X" * 1024 * 256
+    # Kernel MAX_ARG_STRLEN is defined as 32 * PAGE_SIZE
+    max_arg_strlen_bytes = 32 * resource.getpagesize()
+    env["VERY_LARGE_ENV_VAR"] = "X" * max_arg_strlen_bytes
 
     logfile = tmp_path / "logfile"
     echo_output = "Should never appear"
@@ -24,7 +27,7 @@ def test_spawnE2big(capsys, tmp_path):
     with open(logfile) as f:
         logfile_content = f.read()
         assert (
-            "Largest environment variable: VERY_LARGE_ENV_VAR (262164 bytes)"
+            f"Largest environment variable: VERY_LARGE_ENV_VAR 
({max_arg_strlen_bytes + 20} bytes)"
             in logfile_content
         )
     assert retval == 1

Reply via email to