diff options
| author | Dan Halbert <halbert@adafruit.com> | 2019-05-14 15:30:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-14 15:30:44 -0400 |
| commit | d3ce9280e2c00d62c327b25edc271d4ca97c4fae (patch) | |
| tree | 2c076359868e0d3a301eb2834b5835f6c2589c50 /shared-bindings/socket | |
| parent | c6c6171472bcf67d3d9b505e56acb72e86748389 (diff) | |
| parent | e74f5d5d7695ec49bd489dedd35daf2a90c2da21 (diff) | |
Merge pull request #1883 from tannewt/fix_1881
Check native object in case of early access
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); } |
