Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 78932:80909b23ca1e
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
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Mon, 10 Sep 2012 01:25:50 +0200 |
| parents | cdf85b7453c9 |
| children | 8f10c9eae183 dea15868963f |
line wrap: on
line diff
--- a/Modules/socketmodule.c Mon Sep 10 01:23:05 2012 +0200 +++ b/Modules/socketmodule.c Mon Sep 10 01:25:50 2012 +0200 @@ -1674,7 +1674,8 @@ 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);
