pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ludek Finstrle <luf@pzkagis.cz>
To: Hiroshi Inoue <inoue@tpf.co.jp>
Cc: pgsql-odbc@postgresql.org
Subject: Re: Patch for snprintf problem (bug #1000650)
Date: Fri, 9 Jun 2006 14:42:43 +0200
Message-ID: <20060609124243.GA17547@soptik.pzkagis.cz> (raw)
In-Reply-To: <20060609121323.GA17258@soptik.pzkagis.cz>
References: <20060607173910.GA28221@soptik.pzkagis.cz>
	<4488B6EA.9050107@tpf.co.jp>
	<20060609081637.GA8153@soptik.pzkagis.cz>
	<20060609121323.GA17258@soptik.pzkagis.cz>

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

Attachments:

psqlodbc_snprintf_next.diff (text/plain, 1.5K) download 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 {

view thread (5+ messages)

Message-ID: <20060609124243.GA17547@soptik.pzkagis.cz>
Permalink:  ../20060609124243.GA17547@soptik.pzkagis.cz/
Also on:    postgresql.org/message-id/20060609124243.GA17547@soptik.pzkagis.cz

 ·  · 

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-odbc@postgresql.org
  Cc: luf@pzkagis.cz, inoue@tpf.co.jp
  Subject: Re: Patch for snprintf problem (bug #1000650)
  In-Reply-To: <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> <20060609124243.GA17547@soptik.pzkagis.cz>

* 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