summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2012-09-09 23:25:50 (GMT)
committerChristian Heimes <christian@cheimes.de>2012-09-09 23:25:50 (GMT)
commit15b6885fe0ac67a23bbf80f90b1854c3bd7db984 (patch)
tree00f0e607a7680452adc87aec2b3ad3e2bee4a939 /Modules
parent1b3f3b03164fb4b273dd710899adf11b47480231 (diff)
downloadcpython-15b6885fe0ac67a23bbf80f90b1854c3bd7db984.zip
cpython-15b6885fe0ac67a23bbf80f90b1854c3bd7db984.tar.gz
cpython-15b6885fe0ac67a23bbf80f90b1854c3bd7db984.tar.bz2
Make sure that *really* no more than sizeof(ifr.ifr_name) chars are strcpy-ed to ifr.ifr_name and that the string is *always* NUL terminated. New code shouldn't use strcpy(), too. CID 719692
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 7176674..d8c81fe 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1674,7 +1674,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
if (len == 0) {
ifr.ifr_ifindex = 0;
} else if (len < sizeof(ifr.ifr_name)) {
- strcpy(ifr.ifr_name, PyBytes_AS_STRING(interfaceName));
+ strncpy(ifr.ifr_name, PyBytes_AS_STRING(interfaceName), sizeof(ifr.ifr_name));
+ ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0';
if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) {
s->errorhandler();
Py_DECREF(interfaceName);