Re: may be a buffer overflow problem

2024-06-18 Thread Peter Eisentraut
On 18.06.24 04:35, Andres Freund wrote: On 2024-06-17 23:52:54 +0200, Daniel Gustafsson wrote: Since sqlca is, according to our docs, present in other database systems we should probably keep it a 5-char array for portability reasons. Adding a padding character should be fine though. How abou

Re: may be a buffer overflow problem

2024-06-18 Thread Andres Freund
Hi, On 2024-06-17 22:42:41 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2024-06-17 23:52:54 +0200, Daniel Gustafsson wrote: > >> Since sqlca is, according to our docs, present in other database systems we > >> should probably keep it a 5-char array for portability reasons. Adding a > >>

Re: may be a buffer overflow problem

2024-06-17 Thread Tom Lane
Andres Freund writes: > On 2024-06-17 23:52:54 +0200, Daniel Gustafsson wrote: >> Since sqlca is, according to our docs, present in other database systems we >> should probably keep it a 5-char array for portability reasons. Adding a >> padding character should be fine though. > How about, addit

Re: may be a buffer overflow problem

2024-06-17 Thread Andres Freund
Hi, On 2024-06-17 23:52:54 +0200, Daniel Gustafsson wrote: > Since sqlca is, according to our docs, present in other database systems we > should probably keep it a 5-char array for portability reasons. Adding a > padding character should be fine though. How about, additionally, adding __attribu

Re: may be a buffer overflow problem

2024-06-17 Thread Daniel Gustafsson
> On 14 Jun 2024, at 17:18, Tom Lane wrote: > > I wrote: >> Seeing that this code is exercised thousands of times a day in the >> regression tests and has had a failure rate of exactly zero (and >> yes, the tests do check the output), there must be some reason >> why it's okay. > > After looking

Re: may be a buffer overflow problem

2024-06-14 Thread Tom Lane
I wrote: > Seeing that this code is exercised thousands of times a day in the > regression tests and has had a failure rate of exactly zero (and > yes, the tests do check the output), there must be some reason > why it's okay. After looking a little closer, I think the reason why it works in pract

Re: may be a buffer overflow problem

2024-06-14 Thread Tom Lane
Daniel Gustafsson writes: > 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. Seeing that this code is exercised thousands of times a day in the regre

Re:Re: may be a buffer overflow problem

2024-06-14 Thread Winter Loo
>Thanks for looking! I will apply it backpatched all the way down as this has >been wrong since 2006. > >> I wonder how Winter Loo got to see that warning... > I was compiling source code of postgres version 13 and the building flags is changed in my development environment. >And it would be int

Re: may be a buffer overflow problem

2024-06-14 Thread Daniel Gustafsson
> On 14 Jun 2024, at 10:29, Laurenz Albe wrote: > > On Fri, 2024-06-14 at 10:10 +0200, Daniel Gustafsson wrote: >>> On 14 Jun 2024, at 10:06, Laurenz Albe wrote: >> >>> So you think we should ignore that compiler warning? >> >> We already do using this in meson.build: >> >> # Similarly disa

Re: may be a buffer overflow problem

2024-06-14 Thread Laurenz Albe
On Fri, 2024-06-14 at 10:10 +0200, Daniel Gustafsson wrote: > > On 14 Jun 2024, at 10:06, Laurenz Albe wrote: > > > So you think we should ignore that compiler warning? > > We already do using this in meson.build: > >   # Similarly disable useless truncation warnings from gcc 8+ >   'format-tru

Re: may be a buffer overflow problem

2024-06-14 Thread Daniel Gustafsson
> On 14 Jun 2024, at 10:06, Laurenz Albe wrote: > So you think we should ignore that compiler warning? We already do using this in meson.build: # Similarly disable useless truncation warnings from gcc 8+ 'format-truncation', 'stringop-truncation', -- Daniel Gustafsson

Re: may be a buffer overflow problem

2024-06-14 Thread Laurenz Albe
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)); > > ``` > >

Re: may be a buffer overflow problem

2024-06-14 Thread Laurenz Albe
On Fri, 2024-06-14 at 15:38 +0800, Winter Loo wrote: > I am using gcc version 11.3.0 to compile postgres source code. Gcc complains > about the following line: > > strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate)); > > with error as: > > misc.c:529:17: error: ‘strncpy’ output truncat

Re: may be a buffer overflow problem

2024-06-14 Thread Daniel Gustafsson
> 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 anxiou

may be a buffer overflow problem

2024-06-14 Thread Winter Loo
Hi hackers, I am using gcc version 11.3.0 to compile postgres source code. Gcc complains about the following line: ```c strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate)); ``` with error as: misc.c:529:17: error: ‘strncpy’ output truncated before terminating nul copying 5 bytes fr