[PATCH weston] rdp: Check for non-numeric value in RDP_FD env var

Bryce Harrington bryce at osg.samsung.com
Mon Jul 11 20:30:58 UTC 2016


On Fri, Jul 08, 2016 at 08:11:26PM -0700, Yong Bakos wrote:
> On Jul 8, 2016, at 6:54 PM, Bryce Harrington <bryce at osg.samsung.com> wrote:
> > 
> > strtoul(nptr, endptr, ...) will set *endptr to nptr in the case of where
> > no digits were read from the string, and return 0.  Running with
> > RDP_FD=foo would thus result in fd=0 being specified to
> > freerdp_peer_new(), which is unlikely to be the user's intent.
> > 
> > Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> > ---
> > libweston/compositor-rdp.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libweston/compositor-rdp.c b/libweston/compositor-rdp.c
> > index d74dd5e..79f0687 100644
> > --- a/libweston/compositor-rdp.c
> > +++ b/libweston/compositor-rdp.c
> > @@ -1209,6 +1209,7 @@ rdp_backend_create(struct weston_compositor *compositor,
> > {
> > 	struct rdp_backend *b;
> > 	char *fd_str;
> > +	char *fd_tail;
> > 	int fd;
> > 
> > 	b = zalloc(sizeof *b);
> > @@ -1261,8 +1262,8 @@ rdp_backend_create(struct weston_compositor *compositor,
> > 			goto err_output;
> > 		}
> > 
> > -		fd = strtoul(fd_str, NULL, 10);
> > -		if (rdp_peer_init(freerdp_peer_new(fd), b))
> > +		fd = strtoul(fd_str, &fd_tail, 10);
> > +		if (fd_tail == fd_str || rdp_peer_init(freerdp_peer_new(fd), b))
> 
> While you're at it, maybe this deserves to be a little more robust. When
> RDP_FD=42foo, fd_tail will != fd_str and fd will be 42. Something akin to
> the idiom:
> 
> if (fd_tail == fd_str || *fd_tail != '\0' || errno == ERANGE || rdp_peer...

Yeah, good points.  I'll catch this in followup, I think this specific
fix is good on its own, but agree there's more cleanup needed in this
call.  For now I'll push as is.

> Regards,
> yong

Bryce

P.S. Apologies...  When I pushed the patches I thought I'd applied the
patches with your R-b from patchwork but evidently they were my local
copies, so missed your R-b's.  :-/


More information about the wayland-devel mailing list