Tamar Christina <tamar.christ...@arm.com> writes:
> Hi All,
>
> Currently we segfault when len == 0 for an attribute list.
>
> essentially [cons: =0, 1, 2, 3; attrs: ] segfaults but should be equivalent to
> [cons: =0, 1, 2, 3] and [cons: =0, 1, 2, 3; attrs:].  This fixes it by just
> returning early and leaving it to the validators whether this should error out
> or not.
>
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
>
> Ok for master?
>
> Thanks,
> Tamar
>
> gcc/ChangeLog:
>
>       * gensupport.cc (conlist): Support length 0 attribute.
>
> --- inline copy of patch -- 
> diff --git a/gcc/gensupport.cc b/gcc/gensupport.cc
> index 
> 959d1d9c83cf397fcb344e8d3db0f339a967587f..5c5f1cf4781551d3db95103c19cd1b70d98f4f73
>  100644
> --- a/gcc/gensupport.cc
> +++ b/gcc/gensupport.cc
> @@ -619,6 +619,9 @@ public:
>       [ns..ns + len) should equal XSTR (rtx, 0).  */
>    conlist (const char *ns, unsigned int len, bool numeric)
>    {
> +    if (len == 0)
> +      return;
> +
>      /* Trim leading whitespaces.  */
>      while (ISBLANK (*ns))
>        {

I think instead we should add some "len" guards to the while loops:

    /* Trim leading whitespaces.  */
    while (len > 0 && ISBLANK (*ns))
      {
        ns++;
        len--;
      }

    ...

    /* Parse off any modifiers.  */
    while (len > 0 && !ISALNUM (*ns))
      {
        con += *(ns++);
        len--;
      }

Otherwise we could crash for a string that only contains whitespace,
or that only contains non-alphnumeric characters.

OK like that if it works.

Thanks,
Richard

Reply via email to