From f29de5132562cd6e88661d150fa1ee3ab8b771e1 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 13 May 2019 17:31:30 -0700 Subject: Check native object in case of early access If a native displayio object is accessed before it's super().__init__() has been called, then a placeholder is given that will cause a crash if accessed. This is tricky to get right so we detect this case and raise a NotInplementedError instead of crashing. Fixes #1881 --- shared-bindings/socket/__init__.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'shared-bindings/socket') diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c index 8e34c3700..085d4e690 100644 --- a/shared-bindings/socket/__init__.c +++ b/shared-bindings/socket/__init__.c @@ -257,7 +257,7 @@ STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_ //| Reads some bytes from the connected remote address, writing //| into the provided buffer. If bufsize <= len(buffer) is given, //| a maximum of bufsize bytes will be read into the buffer. If no -//| valid value is given for bufsize, the default is the length of +//| valid value is given for bufsize, the default is the length of //| the given buffer. //| //| Suits sockets of type SOCK_STREAM @@ -274,13 +274,14 @@ STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) { } mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); - mp_int_t len; + mp_int_t len = bufinfo.len; if (n_args == 3) { - len = mp_obj_get_int(args[2]); - } - if (n_args == 2 || (size_t) len > bufinfo.len) { - len = bufinfo.len; + mp_int_t given_len = mp_obj_get_int(args[2]); + if (given_len < len) { + len = given_len; + } } + mp_int_t ret = _socket_recv_into(self, (byte*)bufinfo.buf, len); return mp_obj_new_int_from_uint(ret); } -- cgit v1.2.3