[libvirt] [PATCH] Fix parsing of 'info chardev' line endings

This change makes the 'info chardev' parser ignore any trailing whitespace on a line. This fixes a specific problem handling a '\r\n' line ending. * src/qemu/qemu_monitor_text.c: Ignore trailing whitespace in 'info chardev' output. --- src/qemu/qemu_monitor_text.c | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 0cb9ea6..4fd8c4a 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -1622,15 +1622,26 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; } - char *pos = reply; /* The current start of searching */ - char *end = pos + strlen(reply); /* The end of the reply string */ + char *pos; /* The current start of searching */ + char *next = reply; /* The start of the next line */ char *eol; /* The character which ends the current line */ + char *end = reply + strlen(reply); /* The end of the reply string */ + + while (next) { + pos = next; - while (pos < end) { /* Split the output into lines */ eol = memchr(pos, '\n', end - pos); - if (eol == NULL) + if (eol == NULL) { eol = end; + next = NULL; + } else { + next = eol + 1; + } + + /* Ignore all whitespace immediately before eol */ + while (eol > pos && c_isspace(*(eol-1))) + eol -= 1; /* Look for 'filename=pty:' */ #define NEEDLE "filename=pty:" @@ -1638,13 +1649,13 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, /* If it's not there we can ignore this line */ if (!needle) - goto next; + continue; /* id is everthing from the beginning of the line to the ':' * find ':' and turn it into a terminator */ char *colon = memchr(pos, ':', needle - pos); if (colon == NULL) - goto next; + continue; *colon = '\0'; char *id = pos; @@ -1664,9 +1675,6 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; } #undef NEEDLE - - next: - pos = eol + 1; } ret = 0; -- 1.6.5.2

On Mon, Dec 14, 2009 at 03:31:12PM +0000, Matthew Booth wrote:
This change makes the 'info chardev' parser ignore any trailing whitespace on a line. This fixes a specific problem handling a '\r\n' line ending.
* src/qemu/qemu_monitor_text.c: Ignore trailing whitespace in 'info chardev' output. --- src/qemu/qemu_monitor_text.c | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 0cb9ea6..4fd8c4a 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -1622,15 +1622,26 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; }
- char *pos = reply; /* The current start of searching */ - char *end = pos + strlen(reply); /* The end of the reply string */ + char *pos; /* The current start of searching */ + char *next = reply; /* The start of the next line */ char *eol; /* The character which ends the current line */ + char *end = reply + strlen(reply); /* The end of the reply string */ + + while (next) { + pos = next;
- while (pos < end) { /* Split the output into lines */ eol = memchr(pos, '\n', end - pos); - if (eol == NULL) + if (eol == NULL) { eol = end; + next = NULL; + } else { + next = eol + 1; + } + + /* Ignore all whitespace immediately before eol */ + while (eol > pos && c_isspace(*(eol-1))) + eol -= 1;
/* Look for 'filename=pty:' */ #define NEEDLE "filename=pty:" @@ -1638,13 +1649,13 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
/* If it's not there we can ignore this line */ if (!needle) - goto next; + continue;
/* id is everthing from the beginning of the line to the ':' * find ':' and turn it into a terminator */ char *colon = memchr(pos, ':', needle - pos); if (colon == NULL) - goto next; + continue; *colon = '\0'; char *id = pos;
@@ -1664,9 +1675,6 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; } #undef NEEDLE - - next: - pos = eol + 1; }
ret = 0;
ACK, seems this patch got missed which is unfortunate, since it results in XML containining \r in an attribute Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Tue, Jan 05, 2010 at 11:21:01AM +0000, Daniel P. Berrange wrote:
On Mon, Dec 14, 2009 at 03:31:12PM +0000, Matthew Booth wrote:
This change makes the 'info chardev' parser ignore any trailing whitespace on a line. This fixes a specific problem handling a '\r\n' line ending.
* src/qemu/qemu_monitor_text.c: Ignore trailing whitespace in 'info chardev' output. --- src/qemu/qemu_monitor_text.c | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 0cb9ea6..4fd8c4a 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -1622,15 +1622,26 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; }
- char *pos = reply; /* The current start of searching */ - char *end = pos + strlen(reply); /* The end of the reply string */ + char *pos; /* The current start of searching */ + char *next = reply; /* The start of the next line */ char *eol; /* The character which ends the current line */ + char *end = reply + strlen(reply); /* The end of the reply string */ + + while (next) { + pos = next;
- while (pos < end) { /* Split the output into lines */ eol = memchr(pos, '\n', end - pos); - if (eol == NULL) + if (eol == NULL) { eol = end; + next = NULL; + } else { + next = eol + 1; + } + + /* Ignore all whitespace immediately before eol */ + while (eol > pos && c_isspace(*(eol-1))) + eol -= 1;
/* Look for 'filename=pty:' */ #define NEEDLE "filename=pty:" @@ -1638,13 +1649,13 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
/* If it's not there we can ignore this line */ if (!needle) - goto next; + continue;
/* id is everthing from the beginning of the line to the ':' * find ':' and turn it into a terminator */ char *colon = memchr(pos, ':', needle - pos); if (colon == NULL) - goto next; + continue; *colon = '\0'; char *id = pos;
@@ -1664,9 +1675,6 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; } #undef NEEDLE - - next: - pos = eol + 1; }
ret = 0;
ACK, seems this patch got missed which is unfortunate, since it results in XML containining \r in an attribute
Argh, okay, pushed, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Matthew Booth