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 A54439FA621 for ; Fri, 9 Jun 2006 09:40:48 -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 27020-05 for ; Fri, 9 Jun 2006 09:40:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp.pzkagis.cz (gis6.netbox.cz [83.240.30.214]) by postgresql.org (Postfix) with ESMTP id 10A0F9FA61D for ; Fri, 9 Jun 2006 09:40:38 -0300 (ADT) Received: from soptik.pzkagis.cz (localhost.localdomain [127.0.0.1]) by smtp.pzkagis.cz (8.13.1/8.13.1) with ESMTP id k59Cghd6017572; Fri, 9 Jun 2006 14:42:43 +0200 Received: (from luf@localhost) by soptik.pzkagis.cz (8.13.1/8.13.1/Submit) id k59CghcK017571; Fri, 9 Jun 2006 14:42:43 +0200 Date: Fri, 9 Jun 2006 14:42:43 +0200 From: Ludek Finstrle To: Hiroshi Inoue Cc: pgsql-odbc@postgresql.org Subject: Re: Patch for snprintf problem (bug #1000650) Message-ID: <20060609124243.GA17547@soptik.pzkagis.cz> References: <20060607173910.GA28221@soptik.pzkagis.cz> <4488B6EA.9050107@tpf.co.jp> <20060609081637.GA8153@soptik.pzkagis.cz> <20060609121323.GA17258@soptik.pzkagis.cz> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB" Content-Disposition: inline In-Reply-To: <20060609121323.GA17258@soptik.pzkagis.cz> User-Agent: Mutt/1.4.1i X-Virus-Scanned: ClamAV 0.88.2/1523/Fri Jun 9 09:10:10 2006 on smtp.pzkagis.cz X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/52 X-Sequence-Number: 7800 --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Fri, Jun 09, 2006 at 02:13:23PM +0200, Ludek Finstrle napsal(a): > > > > buf = "text"; > > > > snprintf(buf,size,"%s append",buf); > > > > > > > > buf = "text append" on Windows (MS VC compiler) > > > > buf = " append" on linux (gcc compiler) > > > > > > > > I solve it this way (main idea): > > > > snprintf(buf + strlen(buf), " append"); > > > > > > Hmm bad news. > > > If so, it may be better to use the sequence like the following for example. > > > > > > char *query_ptr; > > > size_t bufsize_res; > > > int slen; > > > > > > /* Initialize */ > > > query_ptr = columns_query; > > > bufsize_res = sizeof(columns_query); > > > > > > if (..) > > > { > > > if ((slen = snprintf(query_ptr, bufsize_res, .., )) <= 0) > > > { > > > .. error_handling .. > > > } > > > query_ptr += slen; > > > bufsize_res -= slen; > > > } > > > > > > ... > > > > I'm not sure. There are a lot of strcat, my_strcat, schema_strcat calls > > between snprintf. There is only one place where snprintf could be called > > after another snprintf. > > I change the snprintf_addlen to snprintf_len as you mentioned. I take a look at all snprintf in psqlodbc an I find one more place where it's problematic. If we accept snprintf_add I change one call to it. Additional patch attached, comments are welcome Luf --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="psqlodbc_snprintf_next.diff" diff -c psqlodbc.orig/connection.c psqlodbc/connection.c *** psqlodbc.orig/connection.c 2006-06-06 10:36:53.756768000 +0200 --- psqlodbc/connection.c 2006-06-09 14:35:00.594874796 +0200 *************** *** 2320,2326 **** { if (CC_is_in_error_trans(self)) snprintf(cmd, sizeof(cmd), "ROLLBACK TO %s;", per_query_svp); ! snprintf(cmd, sizeof(cmd), "%sRELEASE %s", cmd, per_query_svp); } else if (CC_is_in_error_trans(self)) strcpy(cmd, "ROLLBACK"); --- 2320,2326 ---- { if (CC_is_in_error_trans(self)) snprintf(cmd, sizeof(cmd), "ROLLBACK TO %s;", per_query_svp); ! snprintf_add(cmd, strlen(cmd), sizeof(cmd), "RELEASE %s", per_query_svp); } else if (CC_is_in_error_trans(self)) strcpy(cmd, "ROLLBACK"); diff -c psqlodbc.orig/results.c psqlodbc/results.c *** psqlodbc.orig/results.c 2006-06-06 10:37:10.131120000 +0200 --- psqlodbc/results.c 2006-06-09 14:36:52.875714241 +0200 *************** *** 2977,2984 **** Int4 slen; /*snprintf(selstr, len, "%s where \"%s\" = %u", stmt->load_statement, bestitem, *oid);*/ snprintf(selstr, len, "%s where ", stmt->load_statement); ! slen = strlen(selstr); ! snprintf(selstr + slen, len - slen, bestqual, *oidint); } else { --- 2977,2983 ---- Int4 slen; /*snprintf(selstr, len, "%s where \"%s\" = %u", stmt->load_statement, bestitem, *oid);*/ snprintf(selstr, len, "%s where ", stmt->load_statement); ! snprintf_add(selstr, strlen(selstr), len, bestqual, *oidint); } else { --DocE+STaALJfprDB--