From: | Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> |
---|---|
To: | exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #16837: Invalid memory access on \h in psql |
Date: | 2021-01-26 11:17:09 |
Message-ID: | 20210126.201709.717799732421886750.horikyota.ntt@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
At Tue, 26 Jan 2021 07:00:00 +0000, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote in
> When executing in psql (under valgrind):
> \h\
>
> valgrind detects the following error:
> ==00:00:00:00.000 3226182==
> ==00:00:00:04.045 3226182== Conditional jump or move depends on
> uninitialised value(s)
> ==00:00:00:04.045 3226182== at 0x1396CB: helpSQL (help.c:600)
> ==00:00:00:04.045 3226182== by 0x120705: exec_command_help
> (command.c:1507)
> ==00:00:00:04.045 3226182== by 0x1252CD: exec_command (command.c:351)
> ==00:00:00:04.045 3226182== by 0x1258A3: HandleSlashCmds
> (command.c:222)
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.
=# \h ALTER VIEX HOGE
<prints help only of "ALTER VIEW"!, not of "ALTER *">
> if (x > 1) /* Nothing on first pass - try the opening
> * word(s) */
> {
> wordlen = j = 1;
!> while (topic[j] != ' ' && j++ < len)
> wordlen++;
> if (x == 2)
> {
> j++;
!> while (topic[j] != ' ' && j++ <= len)
> wordlen++;
> }
So we should check j before accessing topic[j] and count the length
correctly. The attached fixes that. This seems to be very old code.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachment | Content-Type | Size |
---|---|---|
fix-psql-help-parse.patch | text/x-patch | 626 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Tobias Gierke | 2021-01-26 12:56:44 | Assignment to composite type variable fails inside function but running query separately yields correct type & value ? |
Previous Message | Hamid Akhtar | 2021-01-26 09:07:09 | Re: Bug in error reporting for multi-line JSON |