Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B0D1511F7E64 for ; Wed, 20 Jun 2012 02:53:31 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ShDr6-0003uc-GI for pgsql-bugs@postgresql.org; Wed, 20 Jun 2012 05:53:30 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ShDqt-0006bO-0a for pgsql-bugs@postgresql.org; Wed, 20 Jun 2012 05:53:15 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1ShDqs-0007Wj-My for pgsql-bugs@postgresql.org; Wed, 20 Jun 2012 05:53:14 +0000 Date: Wed, 20 Jun 2012 05:53:14 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6700: Potential Bug in numeric.c To: pgsql-bugs@postgresql.org From: msrbugzilla@gmail.com X-Pg-Spam-Score: -1.0 (-) X-Archive-Number: 201206/171 X-Sequence-Number: 33398 The following bug has been logged on the website: Bug reference: 6700 Logged by: Ken Cheung Email address: msrbugzilla@gmail.com PostgreSQL version: Unsupported/Unknown Operating system: Linux Description: = I observed a code clone in the following files. In the function PGTYPESnumeric_copy, the variable dst is ensured to be not NULL before passing to zero_var(). However, the function PGTYPESnumeric_from_decimal does not perform this checking. It will cause an exception when dst is NULL and passed to zero_var(). function : PGTYPESnumeric_copy @ (file: "postgresql-9.2beta2/src/interfaces/ecpg/pgtypeslib/numeric.c", line: 1476)~1491 if (dst =3D=3D NULL) return -1; zero_var(dst); dst->weight =3D src->weight; dst->rscale =3D src->rscale; dst->dscale =3D src->dscale; dst->sign =3D src->sign; if (alloc_var(dst, src->ndigits) !=3D 0) return -1; for (i =3D 0; i < src->ndigits; i++) dst->digits[i] =3D src->digits[i]; return 0; function : PGTYPESnumeric_from_decimal @ (file: "postgresql-9.2beta2/src/interfaces/ecpg/pgtypeslib/numeric.c", line: 1650)~1663 zero_var(dst); dst->weight =3D src->weight; dst->rscale =3D src->rscale; dst->dscale =3D src->dscale; dst->sign =3D src->sign; if (alloc_var(dst, src->ndigits) !=3D 0) return -1; for (i =3D 0; i < src->ndigits; i++) dst->digits[i] =3D src->digits[i]; return 0;