| From: | Andres Freund <andres(at)2ndquadrant(dot)com> | 
|---|---|
| To: | Tomas Vondra <tv(at)fuzzy(dot)cz> | 
| 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:41:45 | 
| Message-ID: | 20131115144145.GB5888@awork2.anarazel.de | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On 2013-11-15 04:21:50 +0100, Tomas Vondra wrote:
> 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.
FWIW, argv0 is pretty much guaranteed to be shorter than MAXPGPATH since
MAXPGPATH is the longest a path can be, and argv[0] is either the executable's
name (if executed via PATH) or the path to the executable.
Now, you could probably write a program to exeve() a binary with argv[0]
being longer, but in that case you can also just put garbage in there.
Greetings,
Andres Freund
-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2013-11-15 14:51:32 | Re: ERROR during end-of-xact/FATAL | 
| Previous Message | Jaime Casanova | 2013-11-15 14:38:45 | Re: Turning recovery.conf into GUCs |