Thread: [PATCH] Fix NULL checking in check_TSCurrentConfig()

[PATCH] Fix NULL checking in check_TSCurrentConfig()

From
Xi Wang
Date:
The correct NULL check should use `*newval'; `newval' must be non-null.
---src/backend/utils/cache/ts_cache.c |    2 +-1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c
index e688b1a..65a8ad7 100644
--- a/src/backend/utils/cache/ts_cache.c
+++ b/src/backend/utils/cache/ts_cache.c
@@ -642,7 +642,7 @@ check_TSCurrentConfig(char **newval, void **extra, GucSource source)        free(*newval);
*newval= strdup(buf);        pfree(buf);
 
-        if (!newval)
+        if (!*newval)            return false;    }
-- 
1.7.10.4




Re: [PATCH] Fix NULL checking in check_TSCurrentConfig()

From
"Dickson S. Guedes"
Date:
2013/1/20 Xi Wang <xi.wang@gmail.com>:
> The correct NULL check should use `*newval'; `newval' must be non-null.

[... cutting code ...]

Please see [1] to know how is our submit patch process.

[1] http://wiki.postgresql.org/wiki/Submitting_a_Patch

regards,
-- 
Dickson S. Guedes
mail/xmpp: guedes@guedesoft.net - skype: guediz
http://github.com/guedes - http://guedesoft.net
http://www.postgresql.org.br



Re: [PATCH] Fix NULL checking in check_TSCurrentConfig()

From
Stephen Frost
Date:
* Xi Wang (xi.wang@gmail.com) wrote:
> The correct NULL check should use `*newval'; `newval' must be non-null.

Why isn't this using pstrdup()..?
Thanks,
    Stephen

Re: [PATCH] Fix NULL checking in check_TSCurrentConfig()

From
Tom Lane
Date:
Stephen Frost <sfrost@snowman.net> writes:
> * Xi Wang (xi.wang@gmail.com) wrote:
>> The correct NULL check should use `*newval'; `newval' must be non-null.

> Why isn't this using pstrdup()..?

The GUC API uses malloc, mainly because guc.c can't afford to lose
control on out-of-memory situations.
        regards, tom lane



Re: [PATCH] Fix NULL checking in check_TSCurrentConfig()

From
Tom Lane
Date:
Xi Wang <xi.wang@gmail.com> writes:
> The correct NULL check should use `*newval'; `newval' must be non-null.

Great catch, will commit.  (But first I'm looking through commit
2594cf0e to see if I made the same mistake anywhere else :-(.)

How did you find that, coverity or some such tool?
        regards, tom lane



Re: [PATCH] Fix NULL checking in check_TSCurrentConfig()

From
Xi Wang
Date:
On 1/20/13 10:35 PM, Tom Lane wrote:
> Great catch, will commit.  (But first I'm looking through commit
> 2594cf0e to see if I made the same mistake anywhere else :-(.)
>
> How did you find that, coverity or some such tool?

Thanks for reviewing the patch.

It was found using a homemade static undefined behavior checker.

- xi