Re: strncpy is not a safe version of strcpy - Mailing list pgsql-hackers

From Andres Freund
Subject Re: strncpy is not a safe version of strcpy
Date
Msg-id 20131115143503.GA5888@awork2.anarazel.de
Whole thread Raw
In response to Re: strncpy is not a safe version of strcpy  (Stephen Frost <sfrost@snowman.net>)
List pgsql-hackers
On 2013-11-15 09:24:59 -0500, Stephen Frost wrote:
> * Tomas Vondra (tv@fuzzy.cz) wrote:
> > On 15 Listopad 2013, 1:00, David Rowley wrote:
> > > more focused on trying to draw a bit of attention to commit
> > > 061b88c732952c59741374806e1e41c1ec845d50 which uses strncpy and does not
> > > properly set the last byte to 0 afterwards. I think this case could just
> > > be
> > > replaced with strlcpy which does all this hard work for us.
> > 
> > Hmm, you mean this piece of code?
> > 
> >    strncpy(saved_argv0, argv[0], MAXPGPATH);
> > 
> > IMHO you're right that's probably broken, unless there's some checking
> > happening before the call.
> 
> Agreed, that looks like a place we should be using strlcpy() instead.

I don't mind fixing it, but I think anything but s/strncpy/strlcpy/ is
over the top. Translating such strings is just a waste of translator's
time.
If you really worry about paths being longer than MAXPGPATH, there's
lots, and lots of things to do that are, far, far more critical than
this.

Greetings,

Andres Freund

-- Andres Freund                       http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training &
Services



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Logging WAL when updating hintbit
Next
From: Merlin Moncure
Date:
Subject: Re: additional json functionality