summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-09-28 18:59:57 -0500
committerJeff Epler <jepler@gmail.com>2020-09-29 19:44:25 -0500
commit176b3376113180ab38fe1c43e2947d358ff041fe (patch)
tree0651442e6f3f9c7f5f6acedd095ece506fc3b039
parent2bb44f6c4d66c5b8f296a5944ada4f704ebadd2b (diff)
rgbmatrix: validate width= constructor parameter
In #3482, @cwalther noted that, hypothetically, a zero byte allocation could be made in the RGBMatrix constructor. Ensure that width is positive. Height was already checked against the number of RGB pins if it was specified, so zero is ruled out there as well.
-rw-r--r--shared-bindings/rgbmatrix/RGBMatrix.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c
index e4683af92..6a99e1f3d 100644
--- a/shared-bindings/rgbmatrix/RGBMatrix.c
+++ b/shared-bindings/rgbmatrix/RGBMatrix.c
@@ -210,6 +210,10 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
}
}
+ if (args[ARG_width] <= 0) {
+ mp_raise_ValueError(translate("width must be greater than zero"));
+ }
+
preflight_pins_or_throw(clock_pin, rgb_pins, rgb_count, true);
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;