Re: Missing NULL check after calling ecpg_strdup - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Re: Missing NULL check after calling ecpg_strdup
Date
Msg-id CAJ7c6TPHq8=w6H7V+A_=veenFrjQFqVTAyK7bgweX9PL2ko9_w@mail.gmail.com
Whole thread Raw
In response to Re: Missing NULL check after calling ecpg_strdup  (Aleksander Alekseev <aleksander@tigerdata.com>)
Responses Re: Missing NULL check after calling ecpg_strdup
List pgsql-hackers
Hi,

> While working on it I noticed a potentially problematic strcmp call,
> marked with XXX in the patch. I didn't address this issue in v2.

Here is the corrected patch v3. Changes since v2:

```
                for (con = all_connections; con != NULL; con = con->next)
                {
-                       /* XXX strcmp() will segfault if con->name is NULL */
-                       if (strcmp(connection_name, con->name) == 0)
+                       /* Check for NULL to prevent segfault */
+                       if (con->name != NULL &&
strcmp(connection_name, con->name) == 0)
                                break;
                }
                ret = con;
```

I was tired or something and didn't think of this trivial fix.

As a side note it looks like ecpg could use some refactoring, but this
is subject for another patch IMO.



pgsql-hackers by date:

Previous
From: Dmitry Dolgov
Date:
Subject: Re: Changing shared_buffers without restart
Next
From: Aleksander Alekseev
Date:
Subject: Re: Missing NULL check after calling ecpg_strdup