Skip to content

Commit 115afdb

Browse files
committed
unix: socket.getaddrinfo: Port is unsigned value.
Treating it as signed lead to buffer overflow for ports >= 32768.
1 parent cf814b2 commit 115afdb

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

unix/modsocket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ STATIC mp_obj_t mod_socket_getaddrinfo(mp_uint_t n_args, const mp_obj_t *args) {
367367
// getaddrinfo accepts port in string notation, so however
368368
// it may seem stupid, we need to convert int to str
369369
if (MP_OBJ_IS_SMALL_INT(args[1])) {
370-
int port = (short)MP_OBJ_SMALL_INT_VALUE(args[1]);
370+
unsigned port = (unsigned short)MP_OBJ_SMALL_INT_VALUE(args[1]);
371371
char buf[6];
372-
sprintf(buf, "%d", port);
372+
sprintf(buf, "%u", port);
373373
serv = buf;
374374
hints.ai_flags = AI_NUMERICSERV;
375375
#ifdef __UCLIBC_MAJOR__

0 commit comments

Comments
 (0)