On Sun, Dec 29, 2013 at 11:59, Loganaden Velvindron wrote:
> Hi All,
> 
> From NetBSD:
> Close masterfd after reading from it. Found by cppcheck.

This is wrong.

     Proper code using fdopen() with error checking should close(2) fildes in
     case of failure, and fclose(3) the resulting FILE * in case of success.

> 
> 
> Index: src/usr.sbin/user/user.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/user/user.c,v
> retrieving revision 1.98
> diff -u -p -r1.98 user.c
> --- src/usr.sbin/user/user.c  23 Nov 2013 17:14:05 -0000      1.98
> +++ src/usr.sbin/user/user.c  29 Dec 2013 19:55:36 -0000
> @@ -1014,6 +1014,7 @@ adduser(char *login_name, user_t *up)
> pw_abort();
> err(EXIT_FAILURE, "read error on %s", _PATH_MASTERPASSWD);
> }
> +     (void)close(masterfd);
> /* if no uid was specified, get next one in [low_uid..high_uid] range */
> sync_uid_gid = (strcmp(up->u_primgrp, "=uid") == 0);
> if (up->u_uid == UID_MAX) {

Reply via email to