Fix Python 3.10 compatibility (#1897544)

f38
Paul Howarth 4 years ago
parent 01b837d83c
commit d58575d615

@ -0,0 +1,163 @@
--- src/block_template.c
+++ src/block_template.c
@@ -33,6 +33,7 @@
#include <string.h>
#endif
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycrypto_compat.h"
#include "modsupport.h"
@@ -123,7 +124,8 @@ ALGnew(PyObject *self, PyObject *args, P
{
unsigned char *key, *IV;
ALGobject * new=NULL;
- int keylen, IVlen=0, mode=MODE_ECB, segment_size=0;
+ Py_ssize_t keylen, IVlen=0;
+ int mode=MODE_ECB, segment_size=0;
PyObject *counter = NULL;
int counter_shortcut = 0;
#ifdef PCT_ARC2_MODULE
@@ -161,7 +163,7 @@ ALGnew(PyObject *self, PyObject *args, P
{
PyErr_Format(PyExc_ValueError,
"Key must be %i bytes long, not %i",
- KEY_SIZE, keylen);
+ KEY_SIZE, (int)keylen);
return NULL;
}
if (KEY_SIZE==0 && keylen==0)
@@ -242,7 +244,7 @@ ALGnew(PyObject *self, PyObject *args, P
new->st.effective_keylen = effective_keylen;
#endif
- block_init(&(new->st), key, keylen);
+ block_init(&(new->st), key, (int)keylen);
if (PyErr_Occurred())
{
Py_DECREF(new);
@@ -250,7 +252,7 @@ ALGnew(PyObject *self, PyObject *args, P
}
memset(new->IV, 0, BLOCK_SIZE);
memset(new->oldCipher, 0, BLOCK_SIZE);
- memcpy(new->IV, IV, IVlen);
+ memcpy(new->IV, IV, (size_t)IVlen);
new->mode = mode;
new->count=BLOCK_SIZE; /* stores how many bytes in new->oldCipher have been used */
return new;
@@ -265,10 +267,12 @@ ALG_Encrypt(ALGobject *self, PyObject *a
unsigned char *buffer, *str;
unsigned char temp[BLOCK_SIZE];
int i, j, len;
+ Py_ssize_t param_len;
PyObject *result;
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len==0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);
@@ -497,14 +501,16 @@ ALG_Decrypt(ALGobject *self, PyObject *a
unsigned char *buffer, *str;
unsigned char temp[BLOCK_SIZE];
int i, j, len;
+ Py_ssize_t param_len;
PyObject *result;
/* CTR mode decryption is identical to encryption */
if (self->mode == MODE_CTR)
return ALG_Encrypt(self, args);
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len==0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);
--- src/hash_template.c
+++ src/hash_template.c
@@ -30,6 +30,7 @@
#ifdef _HAVE_STDC_HEADERS
#include <string.h>
#endif
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycrypto_compat.h"
@@ -163,7 +164,7 @@ static PyObject *
ALG_update(ALGobject *self, PyObject *args)
{
unsigned char *cp;
- int len;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, "s#", &cp, &len))
return NULL;
@@ -273,7 +274,7 @@ ALG_new(PyObject *self, PyObject *args)
{
ALGobject *new;
unsigned char *cp = NULL;
- int len;
+ Py_ssize_t len;
if ((new = newALGobject()) == NULL)
return NULL;
--- src/stream_template.c
+++ src/stream_template.c
@@ -33,6 +33,7 @@
#include <string.h>
#endif
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycrypto_compat.h"
#include "modsupport.h"
@@ -100,7 +101,7 @@ ALGnew(PyObject *self, PyObject *args, P
{
unsigned char *key;
ALGobject * new;
- int keylen;
+ Py_ssize_t keylen;
new = newALGobject();
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s#", kwlist,
@@ -124,7 +125,7 @@ ALGnew(PyObject *self, PyObject *args, P
"the null string (0 bytes long)");
return NULL;
}
- stream_init(&(new->st), key, keylen);
+ stream_init(&(new->st), key, (int)keylen);
if (PyErr_Occurred())
{
Py_DECREF(new);
@@ -141,10 +142,12 @@ ALG_Encrypt(ALGobject *self, PyObject *a
{
unsigned char *buffer, *str;
int len;
+ Py_ssize_t param_len;
PyObject *result;
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len == 0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);
@@ -173,10 +176,12 @@ ALG_Decrypt(ALGobject *self, PyObject *a
{
unsigned char *buffer, *str;
int len;
+ Py_ssize_t param_len;
PyObject *result;
- if (!PyArg_Parse(args, "s#", &str, &len))
+ if (!PyArg_Parse(args, "s#", &str, &param_len))
return NULL;
+ len = (int)param_len;
if (len == 0) /* Handle empty string */
{
return PyBytes_FromStringAndSize(NULL, 0);

@ -7,7 +7,7 @@
Summary: Cryptography library for Python Summary: Cryptography library for Python
Name: python-crypto Name: python-crypto
Version: 2.6.1 Version: 2.6.1
Release: 32%{?dist} Release: 33%{?dist}
# Mostly Public Domain apart from parts of HMAC.py and setup.py, which are Python # Mostly Public Domain apart from parts of HMAC.py and setup.py, which are Python
License: Public Domain and Python License: Public Domain and Python
URL: http://www.pycrypto.org/ URL: http://www.pycrypto.org/
@ -20,6 +20,7 @@ Patch4: python-crypto-2.6.1-link.patch
Patch5: pycrypto-2.6.1-CVE-2018-6594.patch Patch5: pycrypto-2.6.1-CVE-2018-6594.patch
Patch6: pycrypto-2.6.1-use-os-random.patch Patch6: pycrypto-2.6.1-use-os-random.patch
Patch7: pycrypto-2.6.1-drop-py2.1-support.patch Patch7: pycrypto-2.6.1-drop-py2.1-support.patch
Patch8: python-crypto-2.6.1-python3.10.patch
BuildRequires: coreutils BuildRequires: coreutils
BuildRequires: findutils BuildRequires: findutils
BuildRequires: gcc BuildRequires: gcc
@ -84,6 +85,10 @@ rm -rf src/libtom
# in the code # in the code
%patch7 %patch7
# Fix Python 3.10 compatibility
# https://bugzilla.redhat.com/show_bug.cgi?id=1897544
%patch8
# setup.py doesn't run 2to3 on pct-speedtest.py # setup.py doesn't run 2to3 on pct-speedtest.py
cp pct-speedtest.py pct-speedtest3.py cp pct-speedtest.py pct-speedtest3.py
2to3 -wn pct-speedtest3.py 2to3 -wn pct-speedtest3.py
@ -111,6 +116,9 @@ PYTHONPATH=%{buildroot}%{python3_sitearch} %{__python3} pct-speedtest3.py
%{python3_sitearch}/pycrypto-%{version}-py3.*.egg-info %{python3_sitearch}/pycrypto-%{version}-py3.*.egg-info
%changelog %changelog
* Fri Nov 20 2020 Paul Howarth <paul@city-fan.org> - 2.6.1-33
- Fix Python 3.10 compatibility (#1897544)
* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 2.6.1-32 * Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 2.6.1-32
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild - Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

Loading…
Cancel
Save