Bug 15189

Summary: [python3-fail2ban] PY_SSIZE_T_CLEAN macro must be defined for '#' formats" with python3
Product: [Build System, Metadata & Runtime] Other YP Layers Reporter: SAHEERK <saheer.kottakkadan>
Component: meta-securityAssignee: akuster <akuster808>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Undecided CC: randy.macleod
Version: 4.0   
Target Milestone: 4.0.10   
Hardware: Other   
OS: arm   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description SAHEERK 2023-08-11 12:52:53 UTC
I'm trying to run the python3-fail2ban component built by yocto, but I'm encountering an error related to the PY_SSIZE_T_CLEAN macro. The error message is PY_SSIZE_T_CLEAN macro must be defined for '#' formats.

I have no issues with 'python' dependent fail2ban, issues observed only with 'python3' dependent fail2ban

I've looked into the issue and found that in the Python 3.10 C-API documentation https://docs.python.org/3.10/c-api/arg.html#arg-parsing, it's mentioned that,

"Note:  For all # variants of formats (s#, y#, etc.), the macro PY_SSIZE_T_CLEAN must be defined before including Python.h. On Python 3.9 and older, the type of the length argument is [Py_ssize_t] if the PY_SSIZE_T_CLEAN macro is defined, or int otherwise"

I tried to resolve this issue by defining the PY_SSIZE_T_CLEAN macro before including Python.h. But the issue was not resolved, patch snippet here,
+#ifndef PY_SSIZE_T_CLEAN
+#define PY_SSIZE_T_CLEAN 1
+#endif
#include "Python.h"

Also included CFLAGS += "PY_SSIZE_T_CLEAN " in the python3-fail2ban component. No impact on observation

-------Environment---------------------
*) Fail2Ban version : python3-fail2ban 0.11.2 : https://layers.openembedded.org/layerindex/recipe/304629/
*) OS, including release name/version : Linux built by yocto kirkstone (Yocto Project 4.0)
*) Python dependency: python3 3.10.12 https://layers.openembedded.org/layerindex/recipe/300253/
*) No additional patches or changes
*) No other customization

----------Steps to reproduce----------
1. Created a jail /etc/fail2ban/jail.local with the below data,
[sshd]
enabled = yes
port    = ssh
backend = systemd

2. restarted fail2ban services: sudo systemctl restart fail2ban.service

3. Relevant parts of /var/log/fail2ban.log file:
fail2ban-server[11527]: fail2ban                [11527]: ERROR   NOK: ("PY_SSIZE_T_CLEAN macro must be defined for '#' formats",)
Comment 1 SAHEERK 2023-08-11 13:51:14 UTC
Environment Info addition: poky version 4.0.4
Comment 2 Randy MacLeod 2023-08-17 14:36:57 UTC
This isn't an oe-core/bitbake bug, please talk with the meta-security maintainers. See the meta-security README
Comment 3 SAHEERK 2023-08-18 11:35:56 UTC
Created a ticket under meta-security: https://bugzilla.yoctoproject.org/show_bug.cgi?id=15198
Comment 4 SAHEERK 2023-08-18 11:36:53 UTC
*** Bug 15198 has been marked as a duplicate of this bug. ***
Comment 5 SAHEERK 2023-08-18 11:38:29 UTC
This bug is the active ticket. Duplicate ticket closed
Comment 6 SAHEERK 2023-08-18 13:53:15 UTC
This link: https://github.com/systemd/python-systemd/issues/107,  helped me to resolve this issue.

So ticket closing