[PATCH libICE 3/3] Make sure string is never NULL

Emil Velikov emil.l.velikov at gmail.com
Mon Sep 4 12:59:14 UTC 2017


On 4 September 2017 at 12:37, walter harms <wharms at bfs.de> wrote:
>
>
> Am 04.09.2017 13:00, schrieb Emil Velikov:
>> On 7 July 2017 at 11:23, Eric Engestrom <eric.engestrom at imgtec.com> wrote:
>>> `error_message` is passed in to strncpy() without any check, which
>>> doesn't handle NULL itself, so let's make it a valid empty string in
>>> cases where it was NULL.
>>>
>> Strictly speaking strdup() can fail, thus we could still end with a NULL.
>> In all fairness I'm not sure how much one should bother though.
>>
>>
>
> I do not think this is a problem, what the patch catches is the case
>
>         string=ProcessError();
>         ....
>         free(string);
>
> fatal is when the function returns a static string as seen in [PATCH libICE 2/3]
> then you are lost.
I read this a few times and I still cannot parse it, sorry :-\

This patch effectively replaces "foo = NULL;" with "foo = strdup("");"
As strdup fails, you end up in the same situation - foo is NULL.
The failure extremely unlikely, do I doubt it matters.

> Perhaps the whole think can be converted to a preallocated
> buffer, but that would be quit invasive and out of proportion for the problem.
>
Agreed.

-Emil


More information about the xorg-devel mailing list