Re: Patch to implement pg_current_logfile() function

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Christoph Berg <myon(at)debian(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch to implement pg_current_logfile() function
Date: 2016-12-11 03:38:49
Message-ID: 20161210213849.75bc28cc@slate.meme.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 10 Dec 2016 19:41:21 -0600
"Karl O. Pinc" <kop(at)meme(dot)com> wrote:

> On Fri, 9 Dec 2016 23:36:12 -0600
> "Karl O. Pinc" <kop(at)meme(dot)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';

*sigh*

...
char lbuffer[MAXPGPATH];
char *log_format = lbuffer;
...

/* extract log format and log file path from the line */
/* lbuffer == log_format, they share storage */
if (log_filepath = strchr(lbuffer, ' '))
*log_filepath = '\0'; /* terminate log_format */
else
{
/* Unknown format, no space. Return NULL to caller. */
lbuffer[0] = '\0';
break;
}
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(at)meme(dot)com>
> Free Software: "You don't pay back, you pay forward."
> -- Robert A. Heinlein
>

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2016-12-11 06:07:43 Re: Proposal : Parallel Merge Join
Previous Message Peter Geoghegan 2016-12-11 02:44:02 Re: Proposal : Parallel Merge Join