Skip to content

Commit 6b8bcb6

Browse files
robert-hhdpgeorge
authored andcommitted
extmod/modos: Raise an error at a negative argument of os.urandom().
Fixes issue micropython#18825. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent 2e62b56 commit 6b8bcb6

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

extmod/modos.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify)
149149
// This wraps the port-specific mp_hal_get_random(), which is usually defined in mphalport.c.
150150
static mp_obj_t mp_os_urandom(mp_obj_t num) {
151151
mp_int_t n = mp_obj_get_int(num);
152+
if (n < 0) {
153+
mp_raise_ValueError(NULL);
154+
}
152155
vstr_t vstr;
153156
vstr_init_len(&vstr, n);
154157
mp_hal_get_random(n, (uint8_t *)vstr.buf);

0 commit comments

Comments
 (0)