pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Patch for snprintf problem (bug #1000650) 5-th try
3+ messages / 2 participants
[nested] [flat]

* Re: Patch for snprintf problem (bug #1000650) 5-th try
@ 2006-06-14 07:50 Ludek Finstrle <luf@pzkagis.cz>
  2006-06-14 21:28 ` Re: Patch for snprintf problem (bug #1000650) 5-th try Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 3+ messages in thread

From: Ludek Finstrle @ 2006-06-14 07:50 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc

Tue, Jun 13, 2006 at 11:12:58PM +0900, Hiroshi Inoue wrote:
> Ludek Finstrle wrote:
> >
> > I make patch againist CVS after yours huge commit. What's your opinion?
> >   
> 
> Is the second parameter of snprintf_add needed ?
> Aren't the parameter values always strlen(the first parameter) ?

You're right. I think more about it and "add" means add to the end
so I changed the patch as you pointed.

> Is snprintf_len needed instead of snprintf ?
> Though the current code ignores snprintf errors, it's simply
> my negligence..

I'm voting for keeping safer snprintf_len. But I can change it if
you wish.

New patch attached.

Regards,

Luf

Attachments:

psqlodbc_snprintf_5try.diff (text/plain, 12.6K) download diff -c psqlodbc.orig/connection.c psqlodbc.snprintf/connection.c *** psqlodbc.orig/connection.c 2006-06-13 11:26:23.073862179 +0200 --- psqlodbc.snprintf/connection.c 2006-06-14 09:39:07.792064600 +0200 *************** *** 2318,2324 **** { 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"); --- 2318,2324 ---- { if (CC_is_in_error_trans(self)) snprintf(cmd, sizeof(cmd), "ROLLBACK TO %s;", per_query_svp); ! snprintf_add(cmd, sizeof(cmd), "RELEASE %s", per_query_svp); } else if (CC_is_in_error_trans(self)) strcpy(cmd, "ROLLBACK"); diff -c psqlodbc.orig/info.c psqlodbc.snprintf/info.c *** psqlodbc.orig/info.c 2006-06-13 11:26:23.482970903 +0200 --- psqlodbc.snprintf/info.c 2006-06-14 09:37:08.789438792 +0200 *************** *** 1955,1965 **** " inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace", sizeof(columns_query)); if (search_by_ids) ! snprintf(columns_query, sizeof(columns_query), "%s and c.oid = %u", columns_query, reloid); else { if (escTableName) ! snprintf(columns_query, sizeof(columns_query), "%s and c.relname %s '%s'", columns_query, like_or_eq, escTableName); schema_strcat1(columns_query, " and n.nspname %s '%.*s'", like_or_eq, escSchemaName, SQL_NTS, szTableName, cbTableName, conn); } strcat(columns_query, ") inner join pg_catalog.pg_attribute a" --- 1955,1965 ---- " inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace", sizeof(columns_query)); if (search_by_ids) ! snprintf_add(columns_query, sizeof(columns_query), " and c.oid = %u", reloid); else { if (escTableName) ! snprintf_add(columns_query, sizeof(columns_query), " and c.relname %s '%s'", like_or_eq, escTableName); schema_strcat1(columns_query, " and n.nspname %s '%.*s'", like_or_eq, escSchemaName, SQL_NTS, szTableName, cbTableName, conn); } strcat(columns_query, ") inner join pg_catalog.pg_attribute a" *************** *** 1969,1978 **** if (search_by_ids) { if (attnum != 0) ! snprintf(columns_query, sizeof(columns_query), "%s and a.attnum = %d", columns_query, attnum); } else if (escColumnName) ! snprintf(columns_query, sizeof(columns_query), "%s and a.attname %s '%s'", columns_query, like_or_eq, escColumnName); strcat(columns_query, " and a.attrelid = c.oid) inner join pg_catalog.pg_type t" " on t.oid = a.atttypid) left outer join pg_attrdef d" --- 1969,1978 ---- if (search_by_ids) { if (attnum != 0) ! snprintf_add(columns_query, sizeof(columns_query), " and a.attnum = %d", attnum); } else if (escColumnName) ! snprintf_add(columns_query, sizeof(columns_query), " and a.attname %s '%s'", like_or_eq, escColumnName); strcat(columns_query, " and a.attrelid = c.oid) inner join pg_catalog.pg_type t" " on t.oid = a.atttypid) left outer join pg_attrdef d" *************** *** 1990,1999 **** " and a.atttypid = t.oid and (a.attnum > 0)", PG_VERSION_LE(conn, 6.2) ? "a.attlen" : "a.atttypmod"); if (escTableName) ! snprintf(columns_query, sizeof(columns_query), "%s and c.relname %s '%s'", columns_query, like_or_eq, escTableName); my_strcat1(columns_query, " and u.usename %s '%.*s'", like_or_eq, escSchemaName, SQL_NTS); if (escColumnName) ! snprintf(columns_query, sizeof(columns_query), "%s and a.attname %s '%s'", columns_query, like_or_eq, escColumnName); strcat(columns_query, " order by c.relname, attnum"); } --- 1990,1999 ---- " and a.atttypid = t.oid and (a.attnum > 0)", PG_VERSION_LE(conn, 6.2) ? "a.attlen" : "a.atttypmod"); if (escTableName) ! snprintf_add(columns_query, sizeof(columns_query), " and c.relname %s '%s'", like_or_eq, escTableName); my_strcat1(columns_query, " and u.usename %s '%.*s'", like_or_eq, escSchemaName, SQL_NTS); if (escColumnName) ! snprintf_add(columns_query, sizeof(columns_query), " and a.attname %s '%s'", like_or_eq, escColumnName); strcat(columns_query, " order by c.relname, attnum"); } *************** *** 2566,2572 **** /* TableName cannot contain a string search pattern */ /* my_strcat(columns_query, " and c.relname = '%.*s'", szTableName, cbTableName); */ if (escTableName) ! snprintf(columns_query, sizeof(columns_query), "%s and c.relname = '%s'", columns_query, escTableName); /* SchemaName cannot contain a string search pattern */ if (conn->schema_support) schema_strcat(columns_query, " and u.nspname = '%.*s'", escSchemaName, SQL_NTS, szTableName, cbTableName, conn); --- 2566,2572 ---- /* TableName cannot contain a string search pattern */ /* my_strcat(columns_query, " and c.relname = '%.*s'", szTableName, cbTableName); */ if (escTableName) ! snprintf_add(columns_query, sizeof(columns_query), " and c.relname = '%s'", escTableName); /* SchemaName cannot contain a string search pattern */ if (conn->schema_support) schema_strcat(columns_query, " and u.nspname = '%.*s'", escSchemaName, SQL_NTS, szTableName, cbTableName, conn); *************** *** 3246,3251 **** --- 3246,3253 ---- char *escSchemaName = NULL, *escTableName = NULL, *escColumnName = NULL; const char *like_or_eq; char column_query[INFO_INQUIRY_LEN]; + int cq_len,cq_size; + char *col_query; BOOL search_pattern; QResultClass *res; *************** *** 3274,3288 **** " table_name, column_name, grantor, grantee," " privilege_type as PRIVILEGE, is_grantable from" " information_schema.column_privileges where true"); if (escSchemaName) ! snprintf(column_query, sizeof(column_query), ! "%s and table_schem = '%s'", column_query, escSchemaName); if (escTableName) ! snprintf(column_query, sizeof(column_query), ! "%s and table_name = '%s'", column_query, escTableName); if (escColumnName) ! snprintf(column_query, sizeof(column_query), ! "%s and column_name %s '%s'", column_query, like_or_eq, escColumnName); if (res = CC_send_query(conn, column_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(res)) { SC_set_error(stmt, STMT_EXEC_ERROR, "PGAPI_ColumnPrivileges query error", func); --- 3276,3306 ---- " table_name, column_name, grantor, grantee," " privilege_type as PRIVILEGE, is_grantable from" " information_schema.column_privileges where true"); + cq_len = strlen(column_query); + cq_size = sizeof(column_query); + col_query = column_query; if (escSchemaName) ! { ! col_query += cq_len; ! cq_size -= cq_len; ! cq_len = snprintf_len(col_query, cq_size, ! " and table_schem = '%s'", escSchemaName); ! ! } if (escTableName) ! { ! col_query += cq_len; ! cq_size -= cq_len; ! cq_len += snprintf_len(col_query, cq_size, ! " and table_name = '%s'", escTableName); ! } if (escColumnName) ! { ! col_query += cq_len; ! cq_size -= cq_len; ! cq_len += snprintf_len(col_query, cq_size, ! " and column_name %s '%s'", like_or_eq, escColumnName); ! } if (res = CC_send_query(conn, column_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(res)) { SC_set_error(stmt, STMT_EXEC_ERROR, "PGAPI_ColumnPrivileges query error", func); *************** *** 4599,4605 **** strcat(proc_query, " has_function_privilege(p.oid, 'EXECUTE')"); my_strcat1(proc_query, " and nspname %s '%.*s'", like_or_eq, escSchemaName, SQL_NTS); if (escProcName) ! snprintf(proc_query, sizeof(proc_query), "%s and proname %s '%s'", proc_query, like_or_eq, escProcName); strcat(proc_query, " order by nspname, proname, p.oid, attnum"); } else --- 4617,4623 ---- strcat(proc_query, " has_function_privilege(p.oid, 'EXECUTE')"); my_strcat1(proc_query, " and nspname %s '%.*s'", like_or_eq, escSchemaName, SQL_NTS); if (escProcName) ! snprintf_add(proc_query, sizeof(proc_query), " and proname %s '%s'", like_or_eq, escProcName); strcat(proc_query, " order by nspname, proname, p.oid, attnum"); } else *************** *** 4609,4615 **** "(not proretset)"); ret_col = 5; if (escProcName) ! snprintf(proc_query, sizeof(proc_query), " and proname %s '%s'", proc_query, like_or_eq, escProcName); strcat(proc_query, " order by proname, proretset"); } if (tres = CC_send_query(conn, proc_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(tres)) --- 4627,4633 ---- "(not proretset)"); ret_col = 5; if (escProcName) ! snprintf_add(proc_query, sizeof(proc_query), " and proname %s '%s'", like_or_eq, escProcName); strcat(proc_query, " order by proname, proretset"); } if (tres = CC_send_query(conn, proc_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(tres)) *************** *** 5144,5150 **** schema_strcat1(proc_query, " nspname %s '%.*s' and", like_or_eq, escSchemaName, SQL_NTS, szTableName, cbTableName, conn); } if (escTableName) ! snprintf(proc_query, sizeof(proc_query), "%s relname %s '%s' and", proc_query, like_or_eq, escTableName); if (conn->schema_support) { strcat(proc_query, " pg_namespace.oid = relnamespace and relkind in ('r', 'v') and"); --- 5162,5168 ---- schema_strcat1(proc_query, " nspname %s '%.*s' and", like_or_eq, escSchemaName, SQL_NTS, szTableName, cbTableName, conn); } if (escTableName) ! snprintf_add(proc_query, sizeof(proc_query), " relname %s '%s' and", like_or_eq, escTableName); if (conn->schema_support) { strcat(proc_query, " pg_namespace.oid = relnamespace and relkind in ('r', 'v') and"); diff -c psqlodbc.orig/misc.c psqlodbc.snprintf/misc.c *** psqlodbc.orig/misc.c 2006-06-06 10:37:01.556841000 +0200 --- psqlodbc.snprintf/misc.c 2006-06-14 09:34:22.160155854 +0200 *************** *** 291,293 **** --- 291,329 ---- } return my_strcat1(buf, fmt, s1, s, len); } + + /* + * snprintf_add is a extension to snprintf + * It add format to buf at given pos + */ + + int + snprintf_add(char *buf, size_t size, const char *format, ...) + { + int len; + size_t pos = strlen(buf); + va_list arglist; + + va_start(arglist, format); + len = vsnprintf(buf + pos, size - pos, format, arglist); + va_end(arglist); + return len; + } + + /* + * snprintf_addlen is a extension to snprintf + * It returns strlen of buf every time (not -1 when truncated) + */ + + int + snprintf_len(char *buf, size_t size, const char *format, ...) + { + int len; + va_list arglist; + + va_start(arglist, format); + if ((len = vsnprintf(buf, size, format, arglist)) < 0) + len = size; + va_end(arglist); + return len; + } diff -c psqlodbc.orig/misc.h psqlodbc.snprintf/misc.h *** psqlodbc.orig/misc.h 2006-06-06 10:37:01.559842000 +0200 --- psqlodbc.snprintf/misc.h 2006-06-14 09:34:33.013040087 +0200 *************** *** 132,137 **** --- 132,139 ---- char *schema_strcat1(char *buf, const char *fmt, const char *s1, const char *s, int len, const char *, int, ConnectionClass *conn); + int snprintf_add(char *buf, size_t size, const char *format, ...); + int snprintf_len(char *buf, size_t size, const char *format, ...); /* #define GET_SCHEMA_NAME(nspname) (stricmp(nspname, "public") ? nspname : "") */ #define GET_SCHEMA_NAME(nspname) (nspname) diff -c psqlodbc.orig/psqlodbc.h psqlodbc.snprintf/psqlodbc.h *** psqlodbc.orig/psqlodbc.h 2006-06-13 11:26:25.151414304 +0200 --- psqlodbc.snprintf/psqlodbc.h 2006-06-13 11:29:26.345567961 +0200 *************** *** 109,114 **** --- 109,115 ---- #define strdup _strdup #define strnicmp _strnicmp #define stricmp _stricmp + #define vsnprintf _vsnprintf #endif #ifndef SQL_ATTR_APP_ROW_DESC diff -c psqlodbc.orig/results.c psqlodbc.snprintf/results.c *** psqlodbc.orig/results.c 2006-06-13 11:26:25.344465609 +0200 --- psqlodbc.snprintf/results.c 2006-06-14 09:37:30.865305613 +0200 *************** *** 3022,3032 **** snprintf(selstr, len, "%s where ctid = currtid(0, '(,)') %s", stmt->load_statement, oideqstr); else if (bestitem && oidint) { - 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 { --- 3022,3030 ---- snprintf(selstr, len, "%s where ctid = currtid(0, '(,)') %s", stmt->load_statement, oideqstr); else if (bestitem && oidint) { /*snprintf(selstr, len, "%s where \"%s\" = %u", stmt->load_statement, bestitem, *oid);*/ snprintf(selstr, len, "%s where ", stmt->load_statement); ! snprintf_add(selstr, len, bestqual, *oidint); } else {
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: Patch for snprintf problem (bug #1000650) 5-th try
  2006-06-14 07:50 Re: Patch for snprintf problem (bug #1000650) 5-th try Ludek Finstrle <luf@pzkagis.cz>
@ 2006-06-14 21:28 ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-06-15 07:10   ` Re: Patch for snprintf problem (bug #1000650) 5-th try Ludek Finstrle <luf@pzkagis.cz>
  0 siblings, 1 reply; 3+ messages in thread

From: Hiroshi Inoue @ 2006-06-14 21:28 UTC (permalink / raw)
  To: Ludek Finstrle <luf@pzkagis.cz>; +Cc: pgsql-odbc

Ludek Finstrle wrote:
> Tue, Jun 13, 2006 at 11:12:58PM +0900, Hiroshi Inoue wrote:
>   
>> Ludek Finstrle wrote:
>>     
>>> I make patch againist CVS after yours huge commit. What's your opinion?
>>>   
>>>       
>> Is the second parameter of snprintf_add needed ?
>> Aren't the parameter values always strlen(the first parameter) ?
>>     
>
> You're right. I think more about it and "add" means add to the end
> so I changed the patch as you pointed.
>
>   
>> Is snprintf_len needed instead of snprintf ?
>> Though the current code ignores snprintf errors, it's simply
>> my negligence..
>>     
>
> I'm voting for keeping safer snprintf_len. But I can change it if
> you wish.
>
> New patch attached.
>   

OK please commit it.

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Patch for snprintf problem (bug #1000650) 5-th try
  2006-06-14 07:50 Re: Patch for snprintf problem (bug #1000650) 5-th try Ludek Finstrle <luf@pzkagis.cz>
  2006-06-14 21:28 ` Re: Patch for snprintf problem (bug #1000650) 5-th try Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-06-15 07:10   ` Ludek Finstrle <luf@pzkagis.cz>
  0 siblings, 0 replies; 3+ messages in thread

From: Ludek Finstrle @ 2006-06-15 07:10 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc

> OK please commit it.

Patch commited.

Thanks,

Luf



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-06-15 07:10 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-14 07:50 Re: Patch for snprintf problem (bug #1000650) 5-th try Ludek Finstrle <luf@pzkagis.cz>
2006-06-14 21:28 ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-06-15 07:10   ` Ludek Finstrle <luf@pzkagis.cz>

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