aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMauro Matteo Cascella <mcascell@redhat.com>2023-05-23 18:30:23 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2023-05-28 13:08:25 +0400
commit4c93ce54e7114aae33100d2ee4f2b36e451a1d06 (patch)
tree9b07ff722c0331548aefff62fabd76ad389d3870
parent1dfea3f212e43bfd59d1e1f40b9776db440b211f (diff)
downloadqemu-4c93ce54e7114aae33100d2ee4f2b36e451a1d06.zip
qemu-4c93ce54e7114aae33100d2ee4f2b36e451a1d06.tar.gz
qemu-4c93ce54e7114aae33100d2ee4f2b36e451a1d06.tar.bz2
ui/cursor: make width/height unsigned 16-bit integer
Although not actually exploitable at the moment, a negative width/height could make datasize wrap around and potentially lead to buffer overflow. Since there is no reason a negative width/height is ever appropriate, modify QEMUCursor struct and cursor_alloc prototype to accept uint16_t. This protects us against accidentally introducing future bugs. Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com> Reported-by: Jacek Halon <jacek.halon@gmail.com> Reported-by: Yair Mizrahi <yairh33@gmail.com> Reported-by: Elsayed El-Refa'ei <e.elrefaei99@gmail.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Message-Id: <20230523163023.608121-1-mcascell@redhat.com>
-rw-r--r--include/ui/console.h4
-rw-r--r--ui/cursor.c3
2 files changed, 4 insertions, 3 deletions
diff --git a/include/ui/console.h b/include/ui/console.h
index 2a8fab0..ae5ec46 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -144,13 +144,13 @@ typedef struct QemuUIInfo {
/* cursor data format is 32bit RGBA */
typedef struct QEMUCursor {
- int width, height;
+ uint16_t width, height;
int hot_x, hot_y;
int refcount;
uint32_t data[];
} QEMUCursor;
-QEMUCursor *cursor_alloc(int width, int height);
+QEMUCursor *cursor_alloc(uint16_t width, uint16_t height);
QEMUCursor *cursor_ref(QEMUCursor *c);
void cursor_unref(QEMUCursor *c);
QEMUCursor *cursor_builtin_hidden(void);
diff --git a/ui/cursor.c b/ui/cursor.c
index 6fe6799..29717b3 100644
--- a/ui/cursor.c
+++ b/ui/cursor.c
@@ -90,11 +90,12 @@ QEMUCursor *cursor_builtin_left_ptr(void)
return cursor_parse_xpm(cursor_left_ptr_xpm);
}
-QEMUCursor *cursor_alloc(int width, int height)
+QEMUCursor *cursor_alloc(uint16_t width, uint16_t height)
{
QEMUCursor *c;
size_t datasize = width * height * sizeof(uint32_t);
+ /* Modern physical hardware typically uses 512x512 sprites */
if (width > 512 || height > 512) {
return NULL;
}