Re: BUG #16200: returned data from ESQL/C FETCH is trampling outside assigned memory for CHAR column

Michael Meskes <[email protected]> Fri, 10 Jan 2020 20:46:42 +0100
Newsgroups gmane.comp.db.postgresql.bugs
Organization PostgreSQL
Message-ID <[email protected]>
--=-IsYLKiju09CaKODi+1OH
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

> I mean with ESQL/C the general term "Embedded SQL in C". Of course I
> do
> know that for PostgreSQL the precompiler is named "ecpg".

No worries, I was just making sure we do not talk about different
things as I have never seen anyone use this abbreviation before.

> Neither do I know if there is some written standard, but char strings

There is.

> IMHO
> should be NULL terminated. Our application expects in this example no
> more than 16 bytes and that's why we provide a host variable as the
> struct member of 17 bytes so the NULL fits into.
>=20
> I digged into the sources of the ecpglib and this small fix solved
> our problem:
> ...

Sure, this fixes your use case, but as I said, I'm not sure it's the
right thing to do for general use.=20

> > Could you please verify if the indicator is set accordingly?=20
>=20
> If I read the docs here=20
> https://www.postgresql.org/docs/11/ecpg-variables.html#ECPG-INDICATORS
> indicator vars are meant to show null values in the table and not the
> string truncation. Am I wrong? We do not use indicators at all, but
> catch the error condition -213.

Sorry, you're right of course. What I meant was the sqlca structure
which includes:

...
char            sqlwarn[8];
        /* Element 0: set to 'W' if at least one other is 'W'   */
        /* 1: if 'W' at least one character string              */
        /* value was truncated when it was                      */
        /* stored into a host variable.             */
...

Michael
--=20
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Meskes at (Debian|Postgresql) dot Org
Jabber: michael at xmpp dot meskes dot org
VfL Borussia! For=C3=A7a Bar=C3=A7a! SF 49ers! Use Debian GNU/Linux, Postgr=
eSQL

--=-IsYLKiju09CaKODi+1OH
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEZ/2RWVGI6sRsEOjtNdhXwLvLOyUFAl4Y1KIACgkQNdhXwLvL
OyXjOxAAycOcLjK9emUwUGIhU+3CiXaWp2mZE+R1FqbAQh0bgj1fhF7CZzG/ZAmj
T/6/8c1D1zaBlgnNuJOrZTT/VynKm6J2OytfAz+VNqzWsulqpY5J4z8ZjkJC0i9B
ib+93Jj8r1jp0/5FykFHGcFJj6w042xPVejOJm60BWNjbn0vprQ1Lz+YOdZmEAKK
oVc42cSKMT55oSeesddvx1Jw0sEEyDUFL5/WfeR503fXBP/ayCEktV4KjeLJpPAC
ciXrbjdqtgikP8K1cA1KBHTFqyE1IdDBrcLu02/hqdXU6YnTXf868RBhx34I6hZX
voMOgIsFpxQuyE5ZbCv8V7vNnRV5SO8lXH2kHgr1M6RoKnbJdvv/gcryBuk9rpeX
aOgucXhprCgz8aAmx8udeSgNSkXjsa8tC61JSoLJD1eBC6OuEO+gOvVWH2Iw6EnZ
0iYtKhDQAYd3caHGHT4yq2EeDM5XFFpxrnHDJAPOOYlslzBN4BTXg04Cm48p2z2P
CWs/R045oWmLuhUy+8B0Ua2rHWLxHjEkv5kR5Ww/vAU2vHM9STwqj/Sw3fFsh+z/
6R+SKs2K3bnAHxfrv3r79WAId7dJxQ6eUKorjQC0wi24MKPiCDJhGosAdR96S7Va
eCQizAqTzadX2gV9dFWN/ryA8ADGWzR/GE2TA4WYskMB4jVqqG8=
=8mMx
-----END PGP SIGNATURE-----

--=-IsYLKiju09CaKODi+1OH--