[Spice-devel] [PATCH usbredir 5/5] Use a named constant for buffer sizing, and check the buffer size.

Jeremy White jwhite at codeweavers.com
Wed Dec 9 14:16:29 PST 2015


Signed-off-by: Jeremy White <jwhite at codeweavers.com>
---
 connectkernel/connectkernel.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/connectkernel/connectkernel.c b/connectkernel/connectkernel.c
index f45cf62..03bd881 100644
--- a/connectkernel/connectkernel.c
+++ b/connectkernel/connectkernel.c
@@ -94,12 +94,14 @@ int connect_unix(char *fname)
     return s;
 }
 
+#define MAX_DEVID_LENGTH            256
+#define MAX_PRINTED_SOCKET_LENGTH     8
 int main(int argc, char *argv[])
 {
         int s;
         int fd;
         int i;
-        char buf[256 + 8];
+        char buf[MAX_DEVID_LENGTH + MAX_PRINTED_SOCKET_LENGTH + 1];
         char *attach_file = "/sys/bus/platform/drivers/usbredir/attach";
         char *devid = NULL;
         char *server = NULL;
@@ -153,6 +155,13 @@ int main(int argc, char *argv[])
             exit(1);
         }
 
+        if (strlen(devid) > MAX_DEVID_LENGTH)
+        {
+            fprintf(stderr, "Error: device id length greater than %d\n", MAX_DEVID_LENGTH);
+            usage(argv[0]);
+            exit(1);
+        }
+
         if (socket)
             s = connect_unix(server);
         else
-- 
2.1.4



More information about the Spice-devel mailing list