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 CAJ7c6TNX+sL6YLdOVcaHhh_aXQzC3ggfw8vcygJhrNbSzcNEig@mail.gmail.com
Whole thread Raw
In response to Re: Missing NULL check after calling ecpg_strdup  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Missing NULL check after calling ecpg_strdup
List pgsql-hackers
Hi,

> I have spent some time rechecking the whole code, and I have
> backpatched this part.  [...]

Many thanks!

> Hmm..  Aren't you missing a va_end(args) in the early exit you are
> adding here?

I do, and it's rather stupid of me. Thanks.

> [...]
> At the end, I finish with the attached, where alloc_failed matters for
> the failure checks with repeated calls of strdup() in ECPGconnect()
> and also the setlocale() case.  This is for HEAD due to how unlikely
> these issues would occur in practice.

v7 may have a compilation warning on Linux:

```
warning: unused variable ‘alloc_failed’ [-Wunused-variable]
```

... because the only use of the variable is hidden under #ifdef's.

Fixed in v8:

```
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -240,9 +240,9 @@ ECPGget_desc(int lineno, const char *desc_name,
int index,...)
                                act_tuple;
        struct variable data_var;
        struct sqlca_t *sqlca = ECPGget_sqlca();
-       bool            alloc_failed = false;
+       bool            alloc_failed = (sqlca == NULL);

-       if (sqlca == NULL)
+       if (alloc_failed)
        {
                ecpg_raise(lineno, ECPG_OUT_OF_MEMORY,
                                   ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
```

This code is also more consistent with what we ended up having in connect.c.

Other than that the patch looks OK to me.

Attachment

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Log prefix missing for subscriber log messages received from publisher
Next
From: Andrei Lepikhov
Date:
Subject: Re: track generic and custom plans in pg_stat_statements