chiark / gitweb /
terminal: verify kernel-returned DRM events are not truncated
authorDavid Herrmann <dh.herrmann@gmail.com>
Tue, 23 Sep 2014 11:51:42 +0000 (13:51 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Tue, 23 Sep 2014 18:05:45 +0000 (20:05 +0200)
Make sure the kernel always returns events properly. This is guaranteed
right now, otherwise, we do something really wrong. But lets be sure and
verify the received values properly. This also silences some coverity
warnings.

src/libsystemd-terminal/grdev-drm.c

index 5c65c09..5393ebf 100644 (file)
@@ -2223,7 +2223,7 @@ static int grdrm_card_io_fn(sd_event_source *s, int fd, uint32_t revents, void *
                 for (i = 0; i < l; i += event->length) {
                         event = (void*)&buf[i];
 
-                        if (i + event->length > l) {
+                        if (i + (ssize_t)sizeof(*event) > l || i + (ssize_t)event->length > l) {
                                 log_debug("grdrm: %s/%s: truncated event", card->base.session->name, card->base.name);
                                 break;
                         }