X-Original-To: pgsql-odbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 8ED259FB401 for ; Fri, 18 Aug 2006 18:30:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 94735-04 for ; Fri, 18 Aug 2006 18:30:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sd.tpf.co.jp (mail.tpf.co.jp [210.161.239.34]) by postgresql.org (Postfix) with SMTP id 1966F9FB3FE for ; Fri, 18 Aug 2006 18:30:22 -0300 (ADT) Received: (qmail 7319 invoked from network); 19 Aug 2006 06:30:20 +0900 X-Authentication: inoue was authenticated by mail.tpf.co.jp at 19 Aug 2006 06:30:20 +0900 Received: from unknown (HELO ?192.168.11.3?) (219.61.40.10) by mail.tpf.co.jp with SMTP; 19 Aug 2006 06:30:20 +0900 Message-ID: <44E6316A.5010301@tpf.co.jp> Date: Sat, 19 Aug 2006 06:30:18 +0900 From: Hiroshi Inoue User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 To: Bart Samwel CC: pgsql-odbc@postgresql.org Subject: Re: Buffer overrun in handle_notice_message() References: <44E5CB09.1040005@samwel.tk> In-Reply-To: <44E5CB09.1040005@samwel.tk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.025 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200608/66 X-Sequence-Number: 8030 Bart Samwel wrote: > Hi all, > > I'd like to report a buffer overrun in handle_notice_message(). > Analysis: when I run a query >4096 characters that has a 'C' at a > specific location (at a specific, small offset before a multiple of > 4096), then the stack is trashed and the driver crashes. The code > fragment: > > for (;;) > { > truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer)); > if (!msgbuffer[0]) > break; > > mylog("%s: 'N' - %s\n", comment, msgbuffer); > qlog("NOTICE from backend during %s: '%s'\n", comment, msgbuffer); > switch (msgbuffer[0]) > { > case 'S': > strncat(msgbuf, msgbuffer + 1, buflen); > strncat(msgbuf, ": ", buflen); > buflen -= (strlen(msgbuffer) + 1); > break; > case 'M': > strncat(msgbuf, msgbuffer + 1, buflen); > msg_truncated = truncated; > break; > case 'C': > if (sqlstate && !sqlstate[0] && strcmp(msgbuffer + 1, > "00000")) > strcpy(sqlstate, msgbuffer + 1); > break; > } > } Hi Bart, Hmm, ISTM I should place the following code at the end of the above loop not after the above code.. while (truncated) truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer)); Actually I do so In handle_error_message(). I would fix it ASAP. Thanks. regards, Hiroshi Inoue