Re: strncpy is not a safe version of strcpy

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tomas Vondra <tv(at)fuzzy(dot)cz>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: strncpy is not a safe version of strcpy
Date: 2013-11-15 14:24:59
Message-ID: 20131115142459.GY17272@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

* Tomas Vondra (tv(at)fuzzy(dot)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.

Robert, what do you think?

Thanks,

Stephen

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2013-11-15 14:28:14 Re: Turning recovery.conf into GUCs
Previous Message Robert Haas 2013-11-15 13:57:21 Re: [PATCH] Sort contents entries in reference documentation