[PPC] Remove extra \0 char inserted on vty by QEMU

Since version 2.11.0, QEMU became bug-compatible with
PowerVM's vty implementation, by inserting a \0 after
every \r going to the guest. Guests are expected to
workaround this issue by removing every \0 immediately
following a \r.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22171
This commit is contained in:
Leandro Lupori 2019-11-29 11:34:11 +00:00
parent 88eb44d74f
commit 0b0c23fee3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=355209

View File

@ -287,6 +287,7 @@ uart_phyp_get(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
{
int err;
int hdr = 0;
uint64_t i, j;
uart_lock(&sc->sc_mtx);
if (sc->inbuflen == 0) {
@ -297,7 +298,7 @@ uart_phyp_get(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
uart_unlock(&sc->sc_mtx);
return (-1);
}
hdr = 1;
hdr = 1;
}
if (sc->inbuflen == 0) {
@ -305,9 +306,6 @@ uart_phyp_get(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
return (0);
}
if (bufsize > sc->inbuflen)
bufsize = sc->inbuflen;
if ((sc->protocol == HVTERMPROT) && (hdr == 1)) {
sc->inbuflen = sc->inbuflen - 4;
/* The VTERM protocol has a 4 byte header, skip it here. */
@ -315,6 +313,29 @@ uart_phyp_get(struct uart_phyp_softc *sc, void *buffer, size_t bufsize)
sc->inbuflen);
}
/*
* Since version 2.11.0, QEMU became bug-compatible with
* PowerVM's vty implementation, by inserting a \0 after
* every \r going to the guest. Guests are expected to
* workaround this issue by removing every \0 immediately
* following a \r.
*/
if (hdr == 1) {
for (i = 0, j = 0; i < sc->inbuflen; i++, j++) {
if (i > j)
sc->phyp_inbuf.str[j] = sc->phyp_inbuf.str[i];
if (sc->phyp_inbuf.str[i] == '\r' &&
i < sc->inbuflen - 1 &&
sc->phyp_inbuf.str[i + 1] == '\0')
i++;
}
sc->inbuflen -= i - j;
}
if (bufsize > sc->inbuflen)
bufsize = sc->inbuflen;
memcpy(buffer, sc->phyp_inbuf.str, bufsize);
sc->inbuflen -= bufsize;
if (sc->inbuflen > 0)