[gnome-settings-daemon/benzea/fix-read-len-check] rfkill: Fix rfkill event read length check




commit 71ebd208458be7c8444c49e2b72115c5002e93c9
Author: Benjamin Berg <bberg redhat com>
Date:   Wed Apr 14 11:55:51 2021 +0200

    rfkill: Fix rfkill event read length check
    
    The kernel may return a short read for rfkill events in case it is using
    an older API version while g-s-d was compiled using the newer struct. As
    this is perfectly valid, we need to check the read length against
    RFKILL_EVENT_SIZE_V1 rather than the size of the struct.

 plugins/rfkill/rfkill-glib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/plugins/rfkill/rfkill-glib.c b/plugins/rfkill/rfkill-glib.c
index 22309dce..380ebc53 100644
--- a/plugins/rfkill/rfkill-glib.c
+++ b/plugins/rfkill/rfkill-glib.c
@@ -273,7 +273,7 @@ op_to_string (unsigned int op)
 }
 
 static void
-print_event (struct rfkill_event *event)
+print_event (struct rfkill_event *event, gsize size)
 {
        g_debug ("RFKILL event: idx %u type %u (%s) op %u (%s) soft %u hard %u",
                 event->idx,
@@ -351,10 +351,10 @@ event_cb (GIOChannel   *source,
                                                  &read,
                                                  NULL);
 
-               while (status == G_IO_STATUS_NORMAL && read == sizeof(event)) {
+               while (status == G_IO_STATUS_NORMAL && read >= RFKILL_EVENT_SIZE_V1) {
                        struct rfkill_event *event_ptr;
 
-                       print_event (&event);
+                       print_event (&event, read);
 
                        event_ptr = g_memdup (&event, sizeof(event));
                        events = g_list_prepend (events, event_ptr);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]