From c675d80d7221411689d0f8ab18386d2f517eed0c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 15 Mar 2026 18:55:37 -0400 Subject: [PATCH] Be more careful about int vs. Oid in ecpglib. Print an OID value inserted into a SQL query with %u not %d. The existing code accidentally fails to malfunction when given an OID above 2^31, but only accidentally; future changes to our SQL parser could perhaps break it. Declare the Oid values that ecpg_type_infocache_push() and ecpg_is_type_an_array() work with as "Oid" not "int". This doesn't have any functional effect, but it's clearer. At the moment I don't see a need to back-patch this. Bug: #19429 Author: fairyfar@msn.com Reviewed-by: Tom Lane Discussion: https://postgr.es/m/19429-aead3b1874be1a99@postgresql.org --- src/interfaces/ecpg/ecpglib/ecpglib_extern.h | 2 +- src/interfaces/ecpg/ecpglib/execute.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h index 949ff66cefc..bea1398fce8 100644 --- a/src/interfaces/ecpg/ecpglib/ecpglib_extern.h +++ b/src/interfaces/ecpg/ecpglib/ecpglib_extern.h @@ -52,7 +52,7 @@ struct ECPGgeneric_bytea struct ECPGtype_information_cache { struct ECPGtype_information_cache *next; - int oid; + Oid oid; enum ARRAY_TYPE isarray; }; diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index bd10fef5748..ba41732dec6 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -145,7 +145,7 @@ next_insert(char *text, int pos, bool questionmarks, bool std_strings) } static bool -ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, int oid, enum ARRAY_TYPE isarray, int lineno) +ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, Oid oid, enum ARRAY_TYPE isarray, int lineno) { struct ECPGtype_information_cache *new_entry = (struct ECPGtype_information_cache *) ecpg_alloc(sizeof(struct ECPGtype_information_cache), lineno); @@ -161,7 +161,7 @@ ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, int oid, enu } static enum ARRAY_TYPE -ecpg_is_type_an_array(int type, const struct statement *stmt, const struct variable *var) +ecpg_is_type_an_array(Oid type, const struct statement *stmt, const struct variable *var) { char *array_query; enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET; @@ -267,7 +267,7 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia if (array_query == NULL) return ECPG_ARRAY_ERROR; - sprintf(array_query, "select typlen from pg_type where oid=%d and typelem<>0", type); + sprintf(array_query, "select typlen from pg_type where oid=%u and typelem<>0", type); query = PQexec(stmt->connection->connection, array_query); ecpg_free(array_query); if (!ecpg_check_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat)) @@ -294,7 +294,8 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia return ECPG_ARRAY_ERROR; ecpg_type_infocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno); - ecpg_log("ecpg_is_type_an_array on line %d: type (%d); C (%d); array (%s)\n", stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no"); + ecpg_log("ecpg_is_type_an_array on line %d: type (%u); C (%d); array (%s)\n", + stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no"); return isarray; }