Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4QwD-00072d-9K for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jan 2021 16:11:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l4QwC-00038u-7u for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Jan 2021 16:11:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4QwC-00038m-24 for pgsql-bugs@lists.postgresql.org; Tue, 26 Jan 2021 16:11:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4QwA-0007ET-1Q for pgsql-bugs@lists.postgresql.org; Tue, 26 Jan 2021 16:11:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 10QGBMOj2176558; Tue, 26 Jan 2021 11:11:22 -0500 From: Tom Lane To: Kyotaro Horiguchi cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16837: Invalid memory access on \h in psql In-reply-to: <20210126.201709.717799732421886750.horikyota.ntt@gmail.com> References: <16837-479bcd56040c71b3@postgresql.org> <20210126.201709.717799732421886750.horikyota.ntt@gmail.com> Comments: In-reply-to Kyotaro Horiguchi message dated "Tue, 26 Jan 2021 20:17:09 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2176556.1611677482.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 26 Jan 2021 11:11:22 -0500 Message-ID: <2176557.1611677482@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Kyotaro Horiguchi writes: > At Tue, 26 Jan 2021 07:00:00 +0000, PG Bug reporting form wrote in = >> When executing in psql (under valgrind): >> \h\ >> valgrind detects the following error: >> =3D=3D00:00:00:00.000 3226182=3D=3D = >> =3D=3D00:00:00:04.045 3226182=3D=3D Conditional jump or move depends on >> uninitialised value(s) > This is reproducible on master HEAD. helpSQL assumes that the first > word is longer than two characters and the second word exists. It also > doesn't care overruns. Addition to those issues, it miscounts the > length of the first two words if the third word exists. Weirdly, valgrind isn't whining about this for me. But I agree that that loop is unsafe. There are other problems too I think: neither the initialization of "output" nor the calculation of nl_count seem to be done sanely. This function really needs thoroughgoing review :-( regards, tom lane