From: Mikko Rasa Date: Fri, 5 Oct 2012 22:50:07 +0000 (+0300) Subject: Make get_device_properties robust against long property values X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d794c15da1e16cd404a0fb3c0e2bf26fdbfa799b;p=pmount-gui.git Make get_device_properties robust against long property values --- diff --git a/main.c b/main.c index ee55972..62d6a6c 100644 --- 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;