Skip site navigation (1) Skip section navigation (2)

Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]

From: Christof Petig <christof(at)petig-baender(dot)de>
To: Michael Meskes <meskes(at)postgresql(dot)org>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Problem with setlocale (found in libecpg) [accessing a memory location after freeing it]
Date: 2001-09-24 07:18:42
Message-ID: 3BAEDE51.EB229159@petig-baender.de (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Hello,

well at first I could not believe what I was seeing ...

Look at the following code (ecpg/lib/execute.c):

   const char *locale=setlocale(LC_NUMERIC, NULL);
   setlocale(LC_NUMERIC, "C");
[....]
   setlocale(LC_NUMERIC, locale);


Well at least on glibc-2.2 it seems that setlocale retuns a pointer to
malloced memory, and frees this pointer on subsequent calls to
setlocale. This is standard conformant and has good reasons. But used as
above it is lethal (but not lethal enough to be easily recognized). So
the content locale points to is freed by the second call to setlocale.

The remedy is easy (given that _no other_ call to setlocale happens
inbetween ...)

   const char *locale=setlocale(LC_NUMERIC, "C");
   [...]
   setlocale(LC_NUMERIC, locale);


So I would kindly ask you to take a second look at every invokation of
setlocale. And to apply the following patch.

Yours
    Christof


Attachment: B_setlocale.patch.gz
Description: application/x-gzip (343 bytes)

Responses

pgsql-hackers by date

Next:From: Dave PageDate: 2001-09-24 07:37:20
Subject: Re: [ODBC] UTF-8 support
Previous:From: Tatsuo IshiiDate: 2001-09-24 07:12:59
Subject: Re: UTF-8 support

pgsql-patches by date

Next:From: Justin CliftDate: 2001-09-24 15:02:52
Subject: Re: Makefiles for building with mingw32 on win32
Previous:From: Gerhard HäringDate: 2001-09-24 04:31:55
Subject: Re: [PATCHES] Makefiles for building with mingw32 on win32

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group