Re: [PATCH] Patch to fix a crash of psql

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: jianggq(at)cn(dot)fujitsu(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Patch to fix a crash of psql
Date: 2012-11-29 10:00:40
Message-ID: 20121129.190040.1426105867643154672.t-ishii@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I confirmed the problem. Also I confirmed your patch fixes the
problem. In addition to this, all the tests in test/mb and
test/regress are passed.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese: http://www.sraoss.co.jp

> hi
>
> When i test psql under multi-lingual and different encoding
> environment,
> I found a crash of psql.
>
> ----------------------------------------------------------------------
> $ export PGCLIENTENCODING=SJIS
> $ psql
> psql (9.2rc1)
> Type "help" for help.
>
> postgres=# \i sql
> CREATE DATABASE
> You are now connected to database "mydb" as user "postgres".
> CREATE SCHEMA
> Segmentation fault (core dumped)
> $
> ----------------------------------------------------------------------
>
> I'm look into this problem and found that
> only some especial character can cause psql crash.
> conditions is:
> 1. some especial character
> (my sql file contains japanese comment "-- コメント" . It can cause
> psql crash.)
> 2. PGCLIENTENCODING is SJIS
> 3. the encoding of input sql file is UTF-8
>
>
> I investigated this problem. The reasons are as follows.
> ----------------------------------------------------------------------
> src/bin/psql/mainloop.c
> -> psql_scan_setup() //Set up to perform lexing of the given input line.
> -->prepare_buffer () //Set up a flex input buffer to scan the given data.
> ---->malloc character buffer.
> ---->set two \0 characters. (Flex wants two \0 characters after the
> actual data.)
> ---->working in an unsafe encoding, the copy has multibyte sequences
> replaced by FFs to avoid fooling the lexer rules.
> ****the encoding of input sql file is different from PGCLIENTENCODING, two
> \0 characters are replaced by FFs. ****
>
> ---->yy_scan_buffer() //Setup the input buffer state to scan directly
> from a user-specified character buffer.
> ****because two \0 characters are replaced by FFs,yy_scan_buffer() return
> 0. input buffer state can not setup correctly.****
>
> -> psql_scan() //Do lexical analysis of SQL command text.
> --> yylex() //The main scanner function which does all the work.
> ****because input buffer state is not setup,so when access the input
> buffer state,segmentation fault is happened.****
> ----------------------------------------------------------------------
>
>
> I modify src/bin/psql/psqlscan.l to resolve this problem.
> The diff file refer to the attachment "psqlscan.l.patch".
>
>
> Regards,
> Jiang Guiqing

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2012-11-29 10:48:07 Re: Bugs in CREATE/DROP INDEX CONCURRENTLY
Previous Message Heikki Linnakangas 2012-11-29 09:06:14 Refactoring standby mode logic