Skip to contentSkip to conversation

usb: fix unbound stack warning for inotify_watchfn

PATCH In review Peter Xu 3 participants 3 messages Mar 9, 2016 – Mar 18, 2016

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 usb: fix unbound stack warning for inotify_watchfn

---
 hw/usb/dev-mtp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/usb/dev-mtp.c +2 -3
index 7391783..76ad64e 100644
@@ -433,12 +433,11 @@ static void inotify_watchfn(void *arg)
     MTPState *s = arg;
     ssize_t bytes;
     /* From the man page: atleast one event can be read */
-    int len = sizeof(struct inotify_event) + NAME_MAX + 1;
     int pos;
-    char buf[len];
+    char buf[sizeof(struct inotify_event) + NAME_MAX + 1];
 
     for (;;) {
-        bytes = read(s->inotifyfd, buf, len);
+        bytes = read(s->inotifyfd, buf, sizeof(buf));
         pos = 0;
 
         if (bytes <= 0) {
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw

hw/usb/dev-mtp.c static void inotify_watchfn(void *arg) · line 440

Quoted 6 lines · Peter Xu
hw/usb/dev-mtp.c +2 -2
-    char buf[len];
+    char buf[sizeof(struct inotify_event) + NAME_MAX + 1];
 
     for (;;) {
-        bytes = read(s->inotifyfd, buf, len);
+        bytes = read(s->inotifyfd, buf, sizeof(buf));

sizeof is good here, since read takes a size in bytes.