Re: [PATCH] auxdisplay: charlcd: fix x/y command parsing

From: Måns Rullgård
Date: Wed Dec 05 2018 - 12:58:31 EST


Miguel Ojeda <miguel.ojeda.sandonis@xxxxxxxxx> writes:

> Hi Mans,
>
> [CC'ing a few people involved previously on this]
>
> On Wed, Dec 5, 2018 at 2:53 PM Mans Rullgard <mans@xxxxxxxxx> wrote:
>>
>> Commit b34050fadb86 ("auxdisplay: charlcd: Fix and clean up handling of
>> x/y commands") fixed some problems by rewriting the parsing code,
>> but also broke things further by removing the check for a complete
>> command before attempting to parse it. As a result, parsing is
>> terminated at the first x or y character.
>
> Why is it necessary to check for ";" to be exactly at the end? Or, in
> other words, what requires it?
>
> If the syntax supported by parse_xy() is wrong for some reason, we
> should fix that (instead of adding a check before calling it).

Suppose the command "\e[Lx0y0;" is written to the device. The
charlcd_write_char() function adds one character at a time to the escape
sequence buffer. Once the 'L' has been seen, it calls
handle_lcd_special_code() after each additional character is added. On
encountering the 'x' this function will attempt to parse the command
using parse_xy(), which fails since it is incomplete. It is nonetheless
reported as processed, and the escape sequence is flushed. The
remainder of the command (i.e. "0y0;") is then displayed as text.

Since parse_xy() can never return success (true) unless there is a
semicolon, it is pointless to call it until we have seen one. With the
characters being added to the buffer one by one, it is enough to check
for semicolon at the end.

BTW, the parsing of this command has been broken since 3.2-rc1 due to
commit 129957069e6a.

--
Måns Rullgård