diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-05-13 17:31:30 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2019-05-13 17:31:30 -0700 |
| commit | f29de5132562cd6e88661d150fa1ee3ab8b771e1 (patch) | |
| tree | 1f3ac8c4779e4badc825d22fac3c38aceb5bb99e /shared-bindings/socket | |
| parent | a6785d7ff74e156c5bcfdd8f46b1cccae41cc3bf (diff) | |
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
Diffstat (limited to 'shared-bindings/socket')
| -rw-r--r-- | shared-bindings/socket/__init__.c | 13 |
1 files changed, 7 insertions, 6 deletions
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); } |
