[meta-networking][PATCH 2/3] python3-scapy: fix UnboundLocalError in interact()
Khem Raj <[email protected]>
| Newsgroups | org.openembedded.lists.openembedded-devel |
|---|---|
| Message-ID | <[email protected]> |
From: Khem Raj <[email protected]> The "Emulate interact()" UTScapy regression test failed: IPython requested but not found ! Using the default Python shell: History is disabled. Traceback (most recent call last): File "/usr/lib/python3.14/site-packages/scapy/main.py", line 857, in interact banner += "\n" UnboundLocalError: cannot access local variable banner where it is not associated with a value scapy.main.interact() only binds "banner" in the branches handling the ipython, ptipython, ptpython and bpython shells. The test asks for ipython, which is not in the image, so scapy falls back to the plain Python shell and leaves "banner" unbound while still running the unconditional "banner += \n" for the caller-supplied mybanner. The test is correct and the bug is in scapy, which still has it in master, so carry a patch initializing banner from banner_text before the shell-specific chain. meta-networking-image-ptest-python3-scapy now reports PASSED=319 FAILED=0, up from PASSED=318 FAILED=1. Signed-off-by: Khem Raj <[email protected]> --- ...-banner-for-the-default-Python-shell.patch | 44 +++++++++++++++++++ .../python/python3-scapy_2.7.0.bb | 1 + 2 files changed, 45 insertions(+) create mode 100644 meta-networking/recipes-devtools/python/python3-scapy/0002-main-initialize-banner-for-the-default-Python-shell.patch diff --git a/meta-networking/recipes-devtools/python/python3-scapy/0002-main-initialize-banner-for-the-default-Python-shell.patch b/meta-networking/recipes-devtools/python/python3-scapy/0002-main-initialize-banner-for-the-default-Python-shell.patch new file mode 100644 index 0000000000..7de0800c31 --- /dev/null +++ b/meta-networking/recipes-devtools/python/python3-scapy/0002-main-initialize-banner-for-the-default-Python-shell.patch @@ -0,0 +1,44 @@ +From 3d1f9f8043e239d6313d9b9c02a9d6ead6c32302 Mon Sep 17 00:00:00 2001 +From: Khem Raj <[email protected]> +Date: Thu, 20 Aug 2026 00:14:29 +0200 +Subject: [PATCH] main: initialize banner for the default Python shell + +interact() only assigns the local variable "banner" in the branches that +handle the ipython, ptipython, ptpython and bpython shells. The plain +Python shell leaves it unbound, so the unconditional + + banner += "\n" + +in the "if mybanner is not None:" block raises + + UnboundLocalError: cannot access local variable 'banner' where it is + not associated with a value + +This is easy to hit: requesting an interpreter that is not installed +(e.g. conf.interactive_shell = "ipython" without IPython) falls back to +conf.interactive_shell = "python", and any caller passing mybanner then +crashes instead of getting a shell. The mybanneronly path happens to be +safe only because it assigns banner = "" first. + +Initialize banner from banner_text before the shell-specific chain so it +is always bound. + +Upstream-Status: Pending + +Signed-off-by: Khem Raj <[email protected]> +--- + scapy/main.py | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/scapy/main.py b/scapy/main.py +index 990f27f..924e6dc 100644 +--- a/scapy/main.py ++++ b/scapy/main.py +@@ -828,6 +828,7 @@ def interact(mydict=None, + # repl.use_ui_colorscheme("scapy") + + # Extend banner text ++ banner = banner_text + if conf.interactive_shell in ["ipython", "ptipython"]: + import IPython + if conf.interactive_shell == "ptipython": diff --git a/meta-networking/recipes-devtools/python/python3-scapy_2.7.0.bb b/meta-networking/recipes-devtools/python/python3-scapy_2.7.0.bb index c21d2eb0e3..35a4c6fc36 100644 --- a/meta-networking/recipes-devtools/python/python3-scapy_2.7.0.bb +++ b/meta-networking/recipes-devtools/python/python3-scapy_2.7.0.bb @@ -19,6 +19,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=b234ee4d69f5fce4486a80fdaf4a4263" SRCREV = "1de09fe85fe5c9d60ea5c6de130374e170b5bc28" SRC_URI = "git://github.com/secdev/scapy.git;branch=master;protocol=https;tag=v${PV} \ file://0001-python3-scapy-skip-ICMP-regression-tests-in-ptest.patch \ + file://0002-main-initialize-banner-for-the-default-Python-shell.patch \ file://run-ptest" UPSTREAM_CHECK_COMMITS = "1"