summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-07-11 00:05:46 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-07-11 00:06:10 +0300
commit115afdb07d10ed9f8c1f886f880a11a77243d2ba (patch)
treee7b65f402c310b856bcc6f6e85cc4c165ab729f3
parentcf814b2d341d138c3f4d03bccb34576b7fa41a32 (diff)
downloadmicropython-115afdb07d10ed9f8c1f886f880a11a77243d2ba.tar.gz
micropython-115afdb07d10ed9f8c1f886f880a11a77243d2ba.zip
unix: socket.getaddrinfo: Port is unsigned value.
Treating it as signed lead to buffer overflow for ports >= 32768.
-rw-r--r--unix/modsocket.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/unix/modsocket.c b/unix/modsocket.c
index 3d9a6ddd3a..63e6738078 100644
--- a/unix/modsocket.c
+++ b/unix/modsocket.c
@@ -367,9 +367,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(mp_uint_t n_args, const mp_obj_t *args) {
// getaddrinfo accepts port in string notation, so however
// it may seem stupid, we need to convert int to str
if (MP_OBJ_IS_SMALL_INT(args[1])) {
- int port = (short)MP_OBJ_SMALL_INT_VALUE(args[1]);
+ unsigned port = (unsigned short)MP_OBJ_SMALL_INT_VALUE(args[1]);
char buf[6];
- sprintf(buf, "%d", port);
+ sprintf(buf, "%u", port);
serv = buf;
hints.ai_flags = AI_NUMERICSERV;
#ifdef __UCLIBC_MAJOR__