Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BR]: PY_SSIZE_T_CLEAN macro must be defined for '#' formats" with python3 #3553

Closed
saheerskt opened this issue Aug 10, 2023 · 2 comments
Closed

Comments

@saheerskt
Copy link

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

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](https://docs.python.org/3.10/c-api/intro.html#c.Py_ssize_t) if the PY_SSIZE_T_CLEAN macro is defined, or int otherwise.

  1. 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"

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

Environment:

  • Fail2Ban version : python3-fail2ban 0.11.2
  • OS, including release name/version : Linux built by yocto kirkstone (Yocto Project 4.0)
  • Python dependency: python3 3.10.12 [no issues with python dependency. We use only python3 in this setup]
  • No additional patches or changes
  • No other customization

The issue:

Steps to reproduce

  1. Created a jail /etc/fail2ban/jail.local with the below data,
[sshd]
enabled = yes
port    = ssh
backend = systemd
  1. restarted fail2ban services: sudo systemctl restart fail2ban.service
  2. Checking the log : cat /var/log/fail2ban.log

Expected behavior

No error expected here, so sshd jail not working

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",)

@sebres
Copy link
Contributor

sebres commented Aug 10, 2023

no issues with python dependency

I don't think so, vice versa it looks like it may be one...
Because of usage of systemd backend (which requires journal.Reader from python-systemd module) I believe it is systemd/python-systemd#107 (seems to be already fixed and a fixed version published on pypi, but probably did not reach your distro/python installation).
To check whether it is really abovementioned issue, try this... here is (successful) output with 3.11 on Debian 12:

$ fail2ban-python --version
Python 3.11.2
$ fail2ban-python -c 'from systemd import journal; print("v:", journal.__version__); j = journal.Reader(); j.add_match(_SYSTEMD_UNIT="sshd"); print("OK")'
v: 235
OK

If you see the error, try to upgrade systemd-python package, e. g. using pip (pip3), like:

pip3 install --upgrade systemd-python
#or
fail2ban-python -m pip install --upgrade systemd-python

or contact your Python installation or OS distribution maintainers.

Thus I'll close it here as 3rd party issue.

@sebres sebres closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2023
@saheerskt
Copy link
Author

This fix helped me to resolve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants