vim-jp / ctags

Use https://ctags.io instead (This was fork of http://ctags.sourceforge.net/)
GNU General Public License v2.0
26 stars 7 forks source link

Fix EncodingMap related memory management bugs #26

Closed masatake closed 9 years ago

masatake commented 9 years ago

--encoding- has two troubles in memory management.

I1. About initializing EncodingMap[0]

EncodingMap[0] is handled special in addLanguageEncoding; EncodingMap[0] is never initialized.

As the result an encoding cannot be specified to ANT parser which is put in EncodingMap[0].

$ ./ctags --encoding-ant=utf-8 c.c zsh: segmentation fault (core dumped) ./ctags --encoding-ant=utf-8 c.c

I2. About freeing EncodingMap[0]

Though EncodingMap[0] is never initialized, it is freed in freeEncodingResources. This causes a crash.

$ ./ctags --encoding-c=utf-8 c.c zsh: segmentation fault (core dumped) ./ctags --encoding-c=utf-8 c.c

I3. About memory leak of EncodingMap[EncodingMapMax]

Valgrind reports a memory object assigned to
EncodingMap[EncodingMapMax], the last slot of array, will never be
freed. freeEncodingResources doesn't free the last one.
(Impact for users may be small.)

In this patch EncodingMap[0] is initialized with NULL when EncodingMapMax is 0. This fixes I1 and I2.

In addition, <', a comparison operator for finding the last slot is replaced with<='. This fixes I3.

Signed-off-by: Masatake YAMATO yamato@redhat.com

mattn commented 9 years ago

ありがとうございます。既にこっちのリポジトリは universal-ctags と差異が多すぎて PR のベースになり得ないですがマージさせて頂きます。 https://github.com/mattn/ctags の方は手でマージしておきます。