Control: tag -1 + patch upstream

The reason for the segmentation faults is that the arguments
passed to several functions are parsed incorrectly in the C
library.
They use the format string "s*" instead of "s", which would
require a Py_buffer structure instead of a C string.

The attached patch fixes this everywhere arguments are parsed
into a C string.

And btw. the upstream homepage seems to have disappeared,
so I don't know where to forward the patch to.

Kind regards,
  Reiner
From 5f649bd4ffd356807f9bf0511fba7bb83e074f5d Mon Sep 17 00:00:00 2001
From: Reiner Herrmann <rei...@reiner-h.de>
Date: Wed, 15 Mar 2017 12:58:43 +0100
Subject: [PATCH] Fix argument parsing in C library

Closes: #857346
---
 debian/patches/fix_argument_parsing | 111 ++++++++++++++++++++++++++++++++++++
 debian/patches/series               |   1 +
 2 files changed, 112 insertions(+)
 create mode 100644 debian/patches/fix_argument_parsing

diff --git a/debian/patches/fix_argument_parsing b/debian/patches/fix_argument_parsing
new file mode 100644
index 0000000..5f3e6a6
--- /dev/null
+++ b/debian/patches/fix_argument_parsing
@@ -0,0 +1,111 @@
+Author: Reiner Herrmann <rei...@reiner-h.de>
+Description: Fix argument parsing of device names
+ PyArg_ParseTuple was called with the format string "s*" to parse the
+ passed device name into a C string.
+ But according to Python C-API documentation, "s*" is used for parsing data
+ into a Py_buffer structure:  https://docs.python.org/2/c-api/arg.html
+ To store it into a C string, "s" has to be used.
+ (Memory doesn't need to be freed, as it is managed by Python.)
+Bug-Debian: https://bugs.debian.org/857346
+
+--- a/python-ethtool/ethtool.c
++++ b/python-ethtool/ethtool.c
+@@ -121,7 +121,7 @@
+ 	const char *devname;
+ 	char hwaddr[20];
+ 
+-	if (!PyArg_ParseTuple(args, "s*", &devname))
++	if (!PyArg_ParseTuple(args, "s", &devname))
+ 		return NULL;
+ 
+ 	/* Setup our request structure. */
+@@ -163,7 +163,7 @@
+ 	const char *devname;
+ 	char ipaddr[20];
+ 
+-	if (!PyArg_ParseTuple(args, "s*", &devname))
++	if (!PyArg_ParseTuple(args, "s", &devname))
+ 		return NULL;
+ 
+ 	/* Setup our request structure. */
+@@ -295,7 +295,7 @@
+ 	const char *devname;
+ 	int fd, err;
+ 
+-	if (!PyArg_ParseTuple(args, "s*", &devname))
++	if (!PyArg_ParseTuple(args, "s", &devname))
+ 		return NULL;
+ 
+ 	/* Setup our request structure. */
+@@ -328,7 +328,7 @@
+ 	const char *devname;
+ 	char netmask[20];
+ 
+-	if (!PyArg_ParseTuple(args, "s*", &devname))
++	if (!PyArg_ParseTuple(args, "s", &devname))
+ 		return NULL;
+ 
+ 	/* Setup our request structure. */
+@@ -368,7 +368,7 @@
+ 	const char *devname;
+ 	char broadcast[20];
+ 
+-	if (!PyArg_ParseTuple(args, "s*", &devname))
++	if (!PyArg_ParseTuple(args, "s", &devname))
+ 		return NULL;
+ 
+ 	/* Setup our request structure. */
+@@ -409,7 +409,7 @@
+ 	char buf[2048];
+ 	const char *devname;
+ 
+-	if (!PyArg_ParseTuple(args, "s*", &devname))
++	if (!PyArg_ParseTuple(args, "s", &devname))
+ 		return NULL;
+ 
+ 	/* Setup our control structures. */
+@@ -479,7 +479,7 @@
+ 	char buf[1024];
+ 	const char *devname;
+ 
+-	if (!PyArg_ParseTuple(args, "s*", &devname))
++	if (!PyArg_ParseTuple(args, "s", &devname))
+ 		return NULL;
+ 
+ 	/* Setup our control structures. */
+@@ -545,7 +545,7 @@
+ 	const char *devname;
+ 	int err = -1;
+ 
+-	if (PyArg_ParseTuple(args, "s*", &devname))
++	if (PyArg_ParseTuple(args, "s", &devname))
+ 		err = send_command(cmd, devname, value);
+ 
+ 	return err;
+@@ -567,7 +567,7 @@
+ 	struct ethtool_value eval;
+ 	const char *devname;
+ 
+-	if (!PyArg_ParseTuple(args, "s*i", &devname, &eval.data))
++	if (!PyArg_ParseTuple(args, "si", &devname, &eval.data))
+ 		return -1;
+ 
+ 	return send_command(cmd, devname, &eval);
+@@ -752,7 +752,7 @@
+ 	const char *devname;
+ 	PyObject *dict;
+ 
+-	if (!PyArg_ParseTuple(args, "s*O", &devname, &dict))
++	if (!PyArg_ParseTuple(args, "sO", &devname, &dict))
+ 		return NULL;
+ 
+ 	if (struct_desc_from_dict(ethtool_coalesce_desc, &coal, dict) != 0)
+@@ -792,7 +792,7 @@
+ 	const char *devname;
+ 	PyObject *dict;
+ 
+-	if (!PyArg_ParseTuple(args, "s*O", &devname, &dict))
++	if (!PyArg_ParseTuple(args, "sO", &devname, &dict))
+ 		return NULL;
+ 
+ 	if (struct_desc_from_dict(ethtool_ringparam_desc, &ring, dict) != 0)
diff --git a/debian/patches/series b/debian/patches/series
index 2495383..8a0c6cb 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
 fix_missing_if.h_include
 gcc5-warning-fixes
+fix_argument_parsing
-- 
2.11.0

Attachment: signature.asc
Description: PGP signature

Reply via email to