[PATCH v3 3/4] nsenter: new applet

Rich Felker dalias at libc.org
Mon Mar 14 20:09:15 UTC 2016


On Mon, Mar 14, 2016 at 10:27:19AM -0400, Mike Frysinger wrote:
> On 14 Mar 2016 11:07, Bartosz Golaszewski wrote:
> > +#ifndef __BB_NAMESPACE_H
> > +#define __BB_NAMESPACE_H
> 
> use a naming style like other busybox headers

And in particular, don't use leading underscores, ever. They're not
available for use by applications.

> > +/*
> > + * Longest possible path to a procfs file used in namespace utils. Must be
> > + * able to contain the '/proc/' string, the '/ns/user' string which is the
> > + * longest namespace name and a 32-bit integer representing the process ID.
> > + */
> > +#define NS_PROC_PATH_MAX (sizeof("/proc//ns/user") + sizeof(pid_t) * 3)
> 
> using the sizeof pid_t as a proxy for how many chars it'd take to render
> a decimal number in ASCII is wonky.  just hardcode it as "10" since that
> is the largest unsigned 32bit number ("4294967296").

I disagree that this is "wonky". It's a simple safe bound for number
of characters needed to print an integer type. Hard-coding a number,
while unlikely to affect any future Linux targets, is a bomb in the
code that could become dangerous if someone reused it on a system with
pid_t larger than 32-bit.

Rich


More information about the busybox mailing list