From aa553b7700376d5eba055b21fa15dd355e1a3939 Mon Sep 17 00:00:00 2001 From: Jacob Champion Date: Tue, 2 Jul 2024 12:26:04 -0700 Subject: [PATCH v23 1/6] Revert ECPG's use of pnstrdup() Commit 0b9466fce added a dependency on fe_memutils' pnstrdup() inside informix.c. This 1) makes it hard to remove fe_memutils from libpgcommon_shlib, and 2) adds an exit() path where it perhaps should not be. (See the !str check after the call to pnstrdup, which looks like it should not be possible.) Revert that part of the patch for now, pending further discussion on the thread. --- src/interfaces/ecpg/compatlib/informix.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c index 8ea89e640a..65a0b2e46c 100644 --- a/src/interfaces/ecpg/compatlib/informix.c +++ b/src/interfaces/ecpg/compatlib/informix.c @@ -175,6 +175,25 @@ deccopy(decimal *src, decimal *target) memcpy(target, src, sizeof(decimal)); } +static char * +ecpg_strndup(const char *str, size_t len) +{ + size_t real_len = strlen(str); + int use_len = (int) ((real_len > len) ? len : real_len); + + char *new = malloc(use_len + 1); + + if (new) + { + memcpy(new, str, use_len); + new[use_len] = '\0'; + } + else + errno = ENOMEM; + + return new; +} + int deccvasc(const char *cp, int len, decimal *np) { @@ -186,8 +205,8 @@ deccvasc(const char *cp, int len, decimal *np) if (risnull(CSTRINGTYPE, cp)) return 0; - str = pnstrdup(cp, len); /* decimal_in always converts the complete - * string */ + str = ecpg_strndup(cp, len); /* decimal_in always converts the complete + * string */ if (!str) ret = ECPG_INFORMIX_NUM_UNDERFLOW; else -- 2.34.1