Re: may be a buffer overflow problem

Поиск
Список
Период
Сортировка
Искать
От
Laurenz Albe
Тема
Re: may be a buffer overflow problem
Дата
Msg-id
e8dc6ede8f30129f2fa90a9d7d936f50a78057f0.camel@cybertec.at
Ответ на
Список
Дерево обсуждения
may be a buffer overflow problem "Winter Loo" <winterloo@126.com>
Re: may be a buffer overflow problem Laurenz Albe <laurenz.albe@cybertec.at>
Re: may be a buffer overflow problem Daniel Gustafsson <daniel@yesql.se>
Re: may be a buffer overflow problem Tom Lane <tgl@sss.pgh.pa.us>
Re: may be a buffer overflow problem Tom Lane <tgl@sss.pgh.pa.us>
Re: may be a buffer overflow problem Daniel Gustafsson <daniel@yesql.se>
Re: may be a buffer overflow problem Andres Freund <andres@anarazel.de>
Re: may be a buffer overflow problem Tom Lane <tgl@sss.pgh.pa.us>
Re: may be a buffer overflow problem Andres Freund <andres@anarazel.de>
Re: may be a buffer overflow problem Peter Eisentraut <peter@eisentraut.org>
Re: may be a buffer overflow problem Laurenz Albe <laurenz.albe@cybertec.at>
Re: may be a buffer overflow problem Daniel Gustafsson <daniel@yesql.se>
Re: may be a buffer overflow problem Laurenz Albe <laurenz.albe@cybertec.at>
Re: may be a buffer overflow problem Daniel Gustafsson <daniel@yesql.se>
Re:Re: may be a buffer overflow problem "Winter Loo" <winterloo@126.com>
On Fri, 2024-06-14 at 09:55 +0200, Daniel Gustafsson wrote:
> > On 14 Jun 2024, at 09:38, Winter Loo  wrote:
> 
> > I find the definition of `sqlca->sqlstate` and it has only 5 bytes. When the statement
> > 
> > ```c
> > strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate));
> > ```
> > 
> > get executed, `sqlca->sqlstate` will have no '\0' byte which makes me anxious when someone prints that as a string.
> 
> sqlstate is defined as not being unterminated fixed-length, leaving the callers
> to handle termination.
> 
> > Indeed, I found the code(in src/interfaces/ecpg/ecpglib/misc.c) does that,
> > 
> > fprintf(debugstream, "[NO_PID]: sqlca: code: %ld, state: %s\n",
> > sqlca->sqlcode, sqlca->sqlstate);
> 
> This is indeed buggy and need to take the length into account, as per the
> attached.  This only happens when in the undocumented regression test debug
> mode which may be why it's gone unnoticed.

So you think we should ignore that compiler warning?
What about using memcpy() instead of strncpy()?

Yours,
Laurenz Albe


В списке pgsql-hackers по дате отправления
От: Laurenz Albe
Дата:
От: Daniel Gustafsson
Дата:
FAQ