aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkraxel <kraxel>2008-10-20 11:51:58 +0000
committerkraxel <kraxel>2008-10-20 11:51:58 +0000
commit92fa8f0a1bb08dbb13822c39798ad569d912e12e (patch)
tree9389b27f23a945d6120a264d50a4ae40829127a9
parent01722fd61193acc013ebf9af2c9b52fb2db04823 (diff)
downloadqemu-gtk-92fa8f0a1bb08dbb13822c39798ad569d912e12e.tar.gz
- make parsing more robust
-rw-r--r--devices.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/devices.c b/devices.c
index a8cb8bd..49d5679 100644
--- a/devices.c
+++ b/devices.c
@@ -151,6 +151,20 @@ static void add_entry(struct qemu_window *win,
" <menuitem action='%s'/>\n", action);
}
+static int skip_line(char *str, int pos)
+{
+ char line[256];
+ int rc, len;
+
+ rc = sscanf(str+pos, "%255[^\r\n]%n", line, &len);
+ if (1 != rc || 0 == len)
+ return 0;
+ fprintf(stderr, "can't parse \"%s\", skipping\n", line);
+ while (str[pos+len] == '\r' || str[pos+len] == '\n')
+ len++;
+ return len;
+}
+
void devices_parse_info_block(struct qemu_window *win, char *str)
{
char name[32], type[16], line[256], *file, *ptr, *xml;
@@ -178,8 +192,12 @@ void devices_parse_info_block(struct qemu_window *win, char *str)
for (pos = 0;; pos += len) {
rc = sscanf(str+pos, "%31[^:]: type=%15s removable=%d %255[^\r\n]%n",
name, type, &removable, line, &len);
- if (rc != 4)
- break;
+ if (rc != 4) {
+ /* parse error, try to skip line */
+ if (0 == (len = skip_line(str, pos)))
+ break;
+ continue;
+ }
while (str[pos+len] == '\r' || str[pos+len] == '\n')
len++;
if (!removable)
@@ -262,8 +280,12 @@ void devices_parse_info_usb(struct qemu_window *win, char *str)
for (pos = 0;; pos += len) {
rc = sscanf(str+pos, " Device %15[^,], Speed %15s Mb/s, Product %63[^\r\n]%n",
device, speed, name, &len);
- if (rc != 3)
- break;
+ if (rc != 3) {
+ /* parse error, try to skip line */
+ if (0 == (len = skip_line(str, pos)))
+ break;
+ continue;
+ }
while (str[pos+len] == '\r' || str[pos+len] == '\n')
len++;
if (debug)
@@ -322,13 +344,17 @@ void devices_parse_info_usbhost(struct qemu_window *win, char *str)
" Device %15[^,], speed %15s Mb/s\n"
" %31[^:]: USB device %x:%x, %63[^\r\n]%n",
device, speed, class, &vendor, &product, name, &len);
- if (rc != 6)
- break;
+ if (rc != 6) {
+ /* parse error, try to skip line */
+ if (0 == (len = skip_line(str, pos)))
+ break;
+ continue;
+ }
while (str[pos+len] == '\r' || str[pos+len] == '\n')
len++;
if (0 == strcmp("Hub", class))
continue;
- if (1 || debug)
+ if (debug)
fprintf(stderr, "%s: %s (%04x:%04x) - %s - %s\n",
__FUNCTION__, device, vendor, product, class, name);