Re: BUG #16190: The usage of NULL pointer in refint.c
Michael Paquier <[email protected]> Mon, 6 Jan 2020 14:18:00 +0900
| Newsgroups | gmane.comp.db.postgresql.bugs |
|---|---|
| Message-ID | <[email protected]> |
--1rguoi8KZGYj2k4L Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jan 06, 2020 at 03:39:36AM +0000, PG Bug reporting form wrote: > We checked the code in file =E2=80=9Crefint.c=E2=80=9D and there is one e= rror occurring in > line 636. This error is caused by the usage of pointer with NULL value. T= he > code in this line is =E2=80=9Cnewp->ident =3D strdup(ident);=E2=80=9D The= pointer =E2=80=9Cnewp=E2=80=9D is > defined by the code in line 615 as =E2=80=9CEPlan *newp;=E2=80=9D and ini= tialized by the > code in line 628 as =E2=80=9Cnewp =3D *eplan + i;=E2=80=9D or in line 632= as =E2=80=9Cnewp =3D *eplan =3D > (EPlan *) malloc(sizeof(EPlan));=E2=80=9D according to different conditio= ns. In the > first condition, the =E2=80=9C*eplan=E2=80=9D is valued by the code =E2= =80=9C*eplan =3D (EPlan *) > realloc(*eplan, (i + 1) * sizeof(EPlan));=E2=80=9D in line 627. We found = the code > hasn=E2=80=99t checked if the process =E2=80=9Crealloc=E2=80=9D and =E2= =80=9Cmalloc=E2=80=9D are success or not > which directly define the value of =E2=80=9C*eplan=E2=80=9D. The program = should check the > effectiveness of the return value of function =E2=80=9Crealloc=E2=80=9D a= nd =E2=80=9Cmalloc=E2=80=9D to > avoid this error. It could be better to switch all that to not use directly system calls, and rely properly on a high-level memory context with palloc-like allocations. There could be also an argument to just remove the module per the lack of attention it is getting, though it is still useful as an example of use for SPI, and the docs mention it for that. -- Michael --1rguoi8KZGYj2k4L Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl4SwwgACgkQnvQgOdby QH3uzA/7BSRKFW4rzedXjfpvpl8OwXQiKoYmVkZ5Uea6hpQ0dkLVABLkhCKfGL5m MHQ8W84nTxzsDyczPo9XE7nB7FKMoJEqUaJpIqyIaDsPws+WBFKXQmJSZmGGG1/1 C3/ouNt9mOe+RKSQyYpGHq1x5EEyNs2LeX979YIa/iNX/wXrCvVV+Z9kJoMZOuhU SwHiSDgV98Ql6WqBxtB91OsywHy+1ZyT3MbZi0oD2jEB25y3svMgVLA1PysgsHi4 VppFdQzLa2vbMkxAzXXRHf26+pG7Rw+bYen+29o2Gbt24Qi7Z9yt4dt2NnJeCZ1R RU76EiR0/fVn/cjVheXLSDVlbNmm1R2Bd/0hXhAcDE2Fz22zj/4073kfWkEjdaci qKbAP5lFdXiqt14HzeARWEMa7MK0qXT0FI6IIF+vWVswvEDxq/ct/GeziKnPjnva F/Net56igapG3LIKMwrlomCttkYen5qlYWUt8pVpr5+9aQy27Ew+R3gIRVmQiPXW nJ7SKLl4Mu97yfEoDbjDr4n1RDjS/UNc5h/nUkV7ozAx0Wj79pT6/qOk0MSqHou7 ZzMvafrB0ge+eln13MNWv6lWhlxFgh9+opfx2NfRUII66YaKnNT7gddfykM2QXft 0XyaLc1NkCLO1Q8tppKu6mwmKaESN1AkdKcGo1IISe3IZqbTdog= =G/U2 -----END PGP SIGNATURE----- --1rguoi8KZGYj2k4L--