[systemd-devel] [RFC][PATCH 2/2] terminal: handle term_utf8_decode returning NULL

David Herrmann dh.herrmann at gmail.com
Sat Sep 13 03:15:11 PDT 2014


Hi

On Sat, Sep 13, 2014 at 11:24 AM,  <philippedeswert at gmail.com> wrote:
> From: Philippe De Swert <philippedeswert at gmail.com>
>
> term_utf8_decode can return NULL. We definitely do not want
> to dereference ucs4_str in case this happens.
> Not really sure on what to return or handle this though.
> ---
>  src/libsystemd-terminal/term-screen.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/src/libsystemd-terminal/term-screen.c b/src/libsystemd-terminal/term-screen.c
> index 67f9056..5124db6 100644
> --- a/src/libsystemd-terminal/term-screen.c
> +++ b/src/libsystemd-terminal/term-screen.c
> @@ -3757,6 +3757,8 @@ int term_screen_feed_text(term_screen *screen, const uint8_t *in, size_t size) {
>           * enough to support old 7bit/8bit modes. */
>          for (i = 0; i < size; ++i) {
>                  ucs4_str = term_utf8_decode(&screen->utf8, &ucs4_len, in[i]);
> +                if(!ucs4_str)
> +                        return 0;

This cannot happen. ucs4_str is only NULL if ucs4_len is 0. In that
case, we never access the string, though. That is, the following
assertion is true:

assert(ucs4_str != NULL || ucs4_len == 0);

Thanks
David

>                  for (j = 0; j < ucs4_len; ++j) {
>                          r = term_parser_feed(screen->parser, &seq, ucs4_str[j]);
>                          if (r < 0) {
> --
> 1.8.3.2
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list