Re: [HACKERS] Out-of-bounds write and incorrect detection of trigger file in pg_standby

2015-01-15 Thread Robert Haas
On Wed, Jan 14, 2015 at 9:27 PM, Michael Paquier wrote: > On Thu, Jan 15, 2015 at 7:13 AM, Robert Haas wrote: >> Instead of doing this: >> >> if (len < sizeof(buf)) >> buf[len] = '\0'; >> >> ...I would suggest making the size of the buffer one greater than the >> size of the read(), a

Re: [HACKERS] Out-of-bounds write and incorrect detection of trigger file in pg_standby

2015-01-14 Thread Michael Paquier
On Thu, Jan 15, 2015 at 7:13 AM, Robert Haas wrote: > Instead of doing this: > > if (len < sizeof(buf)) > buf[len] = '\0'; > > ...I would suggest making the size of the buffer one greater than the > size of the read(), and then always nul-terminating the buffer. It > seems to me that

Re: [HACKERS] Out-of-bounds write and incorrect detection of trigger file in pg_standby

2015-01-14 Thread Robert Haas
On Wed, Jan 14, 2015 at 8:24 AM, Michael Paquier wrote: > In pg_standby.c, we use a 32-byte buffer in CheckForExternalTrigger to > which is read the content of the trigger file defined by -f: > CheckForExternalTrigger(void) > { > charbuf[32]; > [...] > if ((len = read(fd, buf,

[HACKERS] Out-of-bounds write and incorrect detection of trigger file in pg_standby

2015-01-14 Thread Michael Paquier
Hi all, In pg_standby.c, we use a 32-byte buffer in CheckForExternalTrigger to which is read the content of the trigger file defined by -f: CheckForExternalTrigger(void) { charbuf[32]; [...] if ((len = read(fd, buf, sizeof(buf))) < 0) { stuff(); } if (len <