On 18 October 2017 at 17:07, walter harms <[email protected]> wrote:
>
>
> fix a potential null pointer deference error and
>
> IceAllocScratch() do not report size when allocation failes
>
> Signed-off-by: Walter Harms <[email protected]>
>
> ---
>  src/misc.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/src/misc.c b/src/misc.c
> index 87d6335..fdc671d 100644
> --- a/src/misc.c
> +++ b/src/misc.c
> @@ -57,7 +57,10 @@ IceAllocScratch (
>         free (iceConn->scratch);
>
>         iceConn->scratch = malloc (size);
> -       iceConn->scratch_size = size;
> +       if ( !iceConn->scratch )
> +            iceConn->scratch_size = 0;
> +       else
> +            iceConn->scratch_size = size;
We should really update the STORE_STRING to consider IceAllocScratch
failure, scratch_size being 0.
Perhaps as a follow-up?

>      }
>
>      return (iceConn->scratch);
> @@ -415,12 +418,14 @@ _IceAddOpcodeMapping (
>  )
>  {
>      if (hisOpcode <= 0 || hisOpcode > 255)
> -    {
>         return;
Nit: please add a blank line here.

> -    }
> -    else if (iceConn->process_msg_info == NULL)
> +
> +    if (iceConn->process_msg_info == NULL)
>      {
>         iceConn->process_msg_info = malloc (sizeof (_IceProcessMsgInfo));
> +       if ( ! iceConn->process_msg_info )
> +         return;
> +
>         iceConn->his_min_opcode = iceConn->his_max_opcode = hisOpcode;
>      }
>      else if (hisOpcode < iceConn->his_min_opcode)
> @@ -433,6 +438,9 @@ _IceAddOpcodeMapping (
>         iceConn->process_msg_info = malloc (
>             newsize * sizeof (_IceProcessMsgInfo));
>
> +       if ( ! iceConn->process_msg_info )
> +         return;
> +
>         memcpy (&iceConn->process_msg_info[
>             iceConn->his_min_opcode - hisOpcode], oldVec,
>             oldsize * sizeof (_IceProcessMsgInfo));
> @@ -460,6 +468,9 @@ _IceAddOpcodeMapping (
>         iceConn->process_msg_info = malloc (
>             newsize * sizeof (_IceProcessMsgInfo));
>
> +       if ( ! iceConn->process_msg_info )
> +         return;
> +
Gut feeling says that the function can be simplified substantially...
regardless the patch looks good.

Thanks
Emil
_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to