v25-0001-Revert-ECPG-s-use-of-pnstrdup.patch
application/octet-stream
Filename: v25-0001-Revert-ECPG-s-use-of-pnstrdup.patch
Type: application/octet-stream
Part: 3
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v25-0001
Subject: Revert ECPG's use of pnstrdup()
| File | + | − |
|---|---|---|
| src/interfaces/ecpg/compatlib/informix.c | 21 | 2 |
From 76da087e0cd2d3f8cc179a08f675ad02f9fe9871 Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Tue, 2 Jul 2024 12:26:04 -0700
Subject: [PATCH v25 1/7] 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