Re: [HACKERS] Patch to implement pg_current_logfile() function - Mailing list pgsql-hackers

From Karl O. Pinc
Subject Re: [HACKERS] Patch to implement pg_current_logfile() function
Date
Msg-id 20161210194121.0fd10030@slate.meme.com
Whole thread Raw
In response to Re: [HACKERS] Patch to implement pg_current_logfile() function  ("Karl O. Pinc" <kop@meme.com>)
Responses Re: [HACKERS] Patch to implement pg_current_logfile() function
List pgsql-hackers
On Fri, 9 Dec 2016 23:36:12 -0600
"Karl O. Pinc" <kop@meme.com> wrote:

> Instead I propose (code I have not actually executed):
> ...
> char    lbuffer[MAXPGPATH];
> char    *log_format = lbuffer;
> ...
> 
>     /* extract log format and log file path from the line */
>     log_filepath = strchr(lbuffer, ' ');  /* lbuffer == log_format */
>     *log_filepath = '\0';                 /* terminate log_format */
>     log_filepath++;                       /* start of file path */
>     log_filepath[strcspn(log_filepath, "\n")] = '\0';

Er, I guess I prefer the more paranoid, just because who knows
what might have manged to somehow write the file that's read
into lbuffer:

...
char    lbuffer[MAXPGPATH];
char    *log_format = lbuffer;
...
   /* extract log format and log file path from the line */   if (log_filepath = strchr(lbuffer, ' ')) /* lbuffer ==
log_format*/       *log_filepath = '\0';                /* terminate log_format */   log_filepath++;
     /* start of file path */   log_filepath[strcspn(log_filepath, "\n")] = '\0';
 

The file read is, of course, normally written by postgres.  But possibly
writing to unintended memory locations, even virtual address NULL, does
not seem good.

Any feedback from more experienced PG developers as how to best handle
this case would be welcome.

Regards,

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."                -- Robert A. Heinlein



pgsql-hackers by date:

Previous
From: Venkata B Nagothi
Date:
Subject: Re: [HACKERS] Declarative partitioning - another take
Next
From: Peter Geoghegan
Date:
Subject: Re: [HACKERS] Proposal : Parallel Merge Join