]> git.tdb.fi Git - pmount-gui.git/commitdiff
Make get_device_properties robust against long property values
authorMikko Rasa <tdb@tdb.fi>
Fri, 5 Oct 2012 22:50:07 +0000 (01:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 5 Oct 2012 22:50:07 +0000 (01:50 +0300)
main.c

diff --git a/main.c b/main.c
index ee55972c95d8570a7625e7e2c9cb638ca09a39e0..62d6a6cd5619c1414520587b3687dbd0e749ead7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -68,7 +68,8 @@ Property *get_device_properties(char *node)
        }
        else if(pid>0)
        {
-               char buf[256];
+               char *buf;
+               int bufsize;
                int pos = 0;
                int eof = 0;
                Property *props = NULL;
@@ -76,6 +77,9 @@ Property *get_device_properties(char *node)
 
                close(pipe_fd[1]);
 
+               bufsize = 256;
+               buf = (char *)malloc(bufsize);
+
                while(1)
                {
                        int newline;
@@ -86,7 +90,7 @@ Property *get_device_properties(char *node)
                        {
                                int len;
 
-                               len = read(pipe_fd[0], buf+pos, sizeof(buf)-pos);
+                               len = read(pipe_fd[0], buf+pos, bufsize-pos);
                                if(len==0)
                                        eof = 1;
                                else if(len==-1)
@@ -100,7 +104,13 @@ Property *get_device_properties(char *node)
                                        newline = i;
 
                        if(newline<0)
-                               break;
+                       {
+                               if(eof)
+                                       break;
+                               bufsize *= 2;
+                               buf = (char *)realloc(buf, bufsize);
+                               continue;
+                       }
 
                        if(parse_property(buf, newline, &prop)==0)
                        {
@@ -115,6 +125,8 @@ Property *get_device_properties(char *node)
                                break;
                }
 
+               free(buf);
+
                if(props)
                {
                        props[n_props].name = NULL;