mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-10-01 21:46:35 +03:00
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.
This commit is contained in:
committed by
Daniel Veillard
parent
aee70b7482
commit
c0a9b6a533
@@ -1705,15 +1705,26 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pos = reply; /* The current start of searching */
|
char *pos; /* The current start of searching */
|
||||||
char *end = pos + strlen(reply); /* The end of the reply string */
|
char *next = reply; /* The start of the next line */
|
||||||
char *eol; /* The character which ends the current 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 */
|
/* Split the output into lines */
|
||||||
eol = memchr(pos, '\n', end - pos);
|
eol = memchr(pos, '\n', end - pos);
|
||||||
if (eol == NULL)
|
if (eol == NULL) {
|
||||||
eol = end;
|
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:' */
|
/* Look for 'filename=pty:' */
|
||||||
#define NEEDLE "filename=pty:"
|
#define NEEDLE "filename=pty:"
|
||||||
@@ -1721,13 +1732,13 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
/* If it's not there we can ignore this line */
|
/* If it's not there we can ignore this line */
|
||||||
if (!needle)
|
if (!needle)
|
||||||
goto next;
|
continue;
|
||||||
|
|
||||||
/* id is everthing from the beginning of the line to the ':'
|
/* id is everthing from the beginning of the line to the ':'
|
||||||
* find ':' and turn it into a terminator */
|
* find ':' and turn it into a terminator */
|
||||||
char *colon = memchr(pos, ':', needle - pos);
|
char *colon = memchr(pos, ':', needle - pos);
|
||||||
if (colon == NULL)
|
if (colon == NULL)
|
||||||
goto next;
|
continue;
|
||||||
*colon = '\0';
|
*colon = '\0';
|
||||||
char *id = pos;
|
char *id = pos;
|
||||||
|
|
||||||
@@ -1747,9 +1758,6 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
#undef NEEDLE
|
#undef NEEDLE
|
||||||
|
|
||||||
next:
|
|
||||||
pos = eol + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
Reference in New Issue
Block a user