Re: [PATCH] Patch to fix a crash of psql - Mailing list pgsql-hackers
From | Tatsuo Ishii |
---|---|
Subject | Re: [PATCH] Patch to fix a crash of psql |
Date | |
Msg-id | 20121129.190040.1426105867643154672.t-ishii@sraoss.co.jp Whole thread Raw |
In response to | [PATCH] Patch to fix a crash of psql (JiangGuiqing <jianggq@cn.fujitsu.com>) |
Responses |
Re: [PATCH] Patch to fix a crash of psql
(Tatsuo Ishii <ishii@postgresql.org>)
|
List | 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
pgsql-hackers by date: