pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ranier VF <ranier_gyn@hotmail.com>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Use after free? in fe-connect.c:closePGconn
Date: Wed, 15 Jun 2016 21:11:01 +0000
Message-ID: <BLU183-W36C8721B5C151BC8DEFAA7E3550@phx.gbl> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hi,
Postgresql 9.5.3 32 bits
client 32bits libpq.dll with libpq.pdb

All calls of PQfinish is protected by:
if (conn != NULL) {
   PQfinish(conn);
}

In  [d:\pginstaller.auto\postgres.windows\src\interfaces\libpq\fe-connect.c,
closePGconn(PGconn *conn):
Does not check if conn is NULL.

Use after free?

Best regards,

Ranier

----------------------------------------------------------------------------------------------------------------
Error #1: UNINITIALIZED READ: reading 0x0012fbb4-0x0012fbbb 7 byte(s) within 0x0012fb78-0x0012fbbb
# 0 system call NtCreateFile parameter #9
# 1 ntdll.dll!ZwCreateFile                             +0xb      (0x7c90d09c <ntdll.dll+0xd09c>)
# 2 MSWSOCK.dll!?                                      +0x0      (0x71a149c0 <MSWSOCK.dll+0x49c0>)
# 3 WS2_32.dll!WSASocketW                              +0x9c     (0x71a740eb <WS2_32.dll+0x40eb>)
# 4 ngx_open_listening_sockets                          [c:\msys\1.0\nginx-1.10\src\core\ngx_connection.c:448]
# 5 ngx_init_cycle                                      [c:\msys\1.0\nginx-1.10\src\core\ngx_cycle.c:609]
# 6 main                                                [c:\msys\1.0\nginx-1.10\src\core\nginx.c:276]
Note: @0:00:03.954 in thread 3124

Error #2: UNADDRESSABLE ACCESS of freed memory: reading 0x020afd3c-0x020afd40 4 byte(s)
# 0 LIBPQ.dll!closePGconn                  [d:\pginstaller.auto\postgres.windows\src\interfaces\libpq\fe-connect.c:2957]
# 1 LIBPQ.dll!PQfinish                     [d:\pginstaller.auto\postgres.windows\src\interfaces\libpq\fe-connect.c:3055]
# 2 dbd_pgsql_close                        [c:\usr\src\dbd\postgresql\dbd_pgsql.c:279]
# 3 dbd_pgsql_cleanup                      [c:\usr\src\dbd\postgresql\dbd_pgsql.c:297]
# 4 ngx_destroy_pool                       [c:\msys\1.0\nginx-1.10\src\core\ngx_palloc.c:57]
# 5 ngx_master_process_exit                [c:\msys\1.0\nginx-1.10\src\os\win32\ngx_process_cycle.c:562]
# 6 ngx_master_process_cycle               [c:\msys\1.0\nginx-1.10\src\os\win32\ngx_process_cycle.c:235]
# 7 main                                   [c:\msys\1.0\nginx-1.10\src\core\nginx.c:367]
Note: @8:39:35.860 in thread 3124
Note: prev lower malloc:  0x020afcf8-0x020afd08
Note: 0x020afd3c-0x020afd40 overlaps memory 0x020afd28-0x020b0d28 that was freed here:
Note: # 0 replace_free                           [d:\drmemory_package\common\alloc_replace.c:2706]
Note: # 1 ngx_hash_init                          [c:\msys\1.0\nginx-1.10\src\core\ngx_hash.c:426]
Note: # 2 ngx_http_merge_types                   [c:\msys\1.0\nginx-1.10\src\http\ngx_http.c:2089]
Note: # 3 ngx_http_gzip_merge_conf               [c:\msys\1.0\nginx-1.10\src\http\modules\ngx_http_gzip_filter_module.c:1168]
Note: # 4 ngx_http_merge_servers                 [c:\msys\1.0\nginx-1.10\src\http\ngx_http.c:596]
Note: # 5 ngx_http_block                         [c:\msys\1.0\nginx-1.10\src\http\ngx_http.c:268]
Note: instruction: cmp    0x000000b4(%esi) $0xffffffff

Error #3: UNADDRESSABLE ACCESS beyond heap bounds: reading 0x020afd10-0x020afd14 4 byte(s)
# 0 LIBPQ.dll!closePGconn                  [d:\pginstaller.auto\postgres.windows\src\interfaces\libpq\fe-connect.c:2957]
# 1 LIBPQ.dll!PQfinish                     [d:\pginstaller.auto\postgres.windows\src\interfaces\libpq\fe-connect.c:3055]
# 2 dbd_pgsql_close                        [c:\usr\src\dbd\postgresql\dbd_pgsql.c:279]
# 3 dbd_pgsql_cleanup                      [c:\usr\src\dbd\postgresql\dbd_pgsql.c:297]
# 4 ngx_destroy_pool                       [c:\msys\1.0\nginx-1.10\src\core\ngx_palloc.c:57]
# 5 ngx_master_process_exit                [c:\msys\1.0\nginx-1.10\src\os\win32\ngx_process_cycle.c:562]
# 6 ngx_master_process_cycle               [c:\msys\1.0\nginx-1.10\src\os\win32\ngx_process_cycle.c:235]
# 7 main                                   [c:\msys\1.0\nginx-1.10\src\core\nginx.c:367]
Note: @8:39:35.954 in thread 3124
Note: prev lower malloc:  0x020afcf8-0x020afd08
Note: instruction: cmp    0x00000088(%esi) $0x00000000

Error #4: UNADDRESSABLE ACCESS of freed memory: writing 0x020afd2b-0x020afd2c 1 byte(s)
# 0 LIBPQ.dll!closePGconn                  [d:\pginstaller.auto\postgres.windows\src\interfaces\libpq\fe-connect.c:2974]
# 1 LIBPQ.dll!PQfinish                     [d:\pginstaller.auto\postgres.windows\src\interfaces\libpq\fe-connect.c:3055]
# 2 dbd_pgsql_close                        [c:\usr\src\dbd\postgresql\dbd_pgsql.c:279]
# 3 dbd_pgsql_cleanup                      [c:\usr\src\dbd\postgresql\dbd_pgsql.c:297]
# 4 ngx_destroy_pool                       [c:\msys\1.0\nginx-1.10\src\core\ngx_palloc.c:57]
# 5 ngx_master_process_exit                [c:\msys\1.0\nginx-1.10\src\os\win32\ngx_process_cycle.c:562]
# 6 ngx_master_process_cycle               [c:\msys\1.0\nginx-1.10\src\os\win32\ngx_process_cycle.c:235]
# 7 main                                   [c:\msys\1.0\nginx-1.10\src\core\nginx.c:367]
Note: @8:39:35.969 in thread 3124
Note: prev lower malloc:  0x020afcf8-0x020afd08
Note: 0x020afd2b-0x020afd2c overlaps memory 0x020afd28-0x020b0d28 that was freed here:
Note: # 0 replace_free                           [d:\drmemory_package\common\alloc_replace.c:2706]
Note: # 1 ngx_hash_init                          [c:\msys\1.0\nginx-1.10\src\core\ngx_hash.c:426]
Note: # 2 ngx_http_merge_types                   [c:\msys\1.0\nginx-1.10\src\http\ngx_http.c:2089]
Note: # 3 ngx_http_gzip_merge_conf               [c:\msys\1.0\nginx-1.10\src\http\modules\ngx_http_gzip_filter_module.c:1168]
Note: # 4 ngx_http_merge_servers                 [c:\msys\1.0\nginx-1.10\src\http\ngx_http.c:596]
Note: # 5 ngx_http_block                         [c:\msys\1.0\nginx-1.10\src\http\ngx_http.c:268]
Note: instruction: mov    $0x00 -> 0x000000a3(%esi)
-----------------------------------------------------------------------------------------------------------------------
 		 	   		  =

view thread (3+ messages)  latest in thread

Message-ID: <BLU183-W36C8721B5C151BC8DEFAA7E3550@phx.gbl>
Permalink:  ../BLU183-W36C8721B5C151BC8DEFAA7E3550@phx.gbl/
Also on:    postgresql.org/message-id/BLU183-W36C8721B5C151BC8DEFAA7E3550@phx.gbl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: ranier_gyn@hotmail.com
  Subject: Re: Use after free? in fe-connect.c:closePGconn
  In-Reply-To: <BLU183-W36C8721B5C151BC8DEFAA7E3550@phx.gbl>
  References: <BLU183-W36C8721B5C151BC8DEFAA7E3550@phx.gbl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox