From: o.tselebrovskiy@postgrespro.ru
To: pgsql-hackers@postgresql.org
Subject: Returning non-terminated string in ECPG Informix-compatible function
Date: Mon, 29 Jan 2024 11:47:31 +0300
Message-ID: <bf47888585149f83b276861a1662f7e4@postgrespro.ru> (raw)
Greetings, everyone!
While analyzing output of Svace static analyzer [1] I've found a bug.
In function intoasc(interval * i, char *str) from file
src/interfaces/ecpg/compatlib/informix.c
we return a non-terminated string since we use memcpy on tmp which is
itself NULL-teminated but
last zero byte is not copied.
The proposed solution is to use strcpy instead, since it is used in all
other functions in informix.c.
The patch is attached.
[1] - https://svace.pages.ispras.ru/svace-website/en/
Oleg Tselebrovskiy, Postgres Pro
Attachments:
[text/x-diff] informix_null_terminator.patch (395B, ../bf47888585149f83b276861a1662f7e4@postgrespro.ru/2-informix_null_terminator.patch)
download | inline diff:diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.cindex dccf39582da..80d40aa3e09 100644--- a/src/interfaces/ecpg/compatlib/informix.c+++ b/src/interfaces/ecpg/compatlib/informix.c@@ -654,7 +654,7 @@ intoasc(interval * i, char *str)
if (!tmp)
return -errno;
- memcpy(str, tmp, strlen(tmp));+ strcpy(str, tmp);
free(tmp);
return 0;
}
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: o.tselebrovskiy@postgrespro.ru
Subject: Re: Returning non-terminated string in ECPG Informix-compatible function
In-Reply-To: <bf47888585149f83b276861a1662f7e4@postgrespro.ru>
* 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