Deleted Added
full compact
bsd-closefrom.c (137015) bsd-closefrom.c (157016)
1/*
2 * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 32 unchanged lines hidden (view full) ---

41# include <ndir.h>
42# endif
43#endif
44
45#ifndef OPEN_MAX
46# define OPEN_MAX 256
47#endif
48
1/*
2 * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 32 unchanged lines hidden (view full) ---

41# include <ndir.h>
42# endif
43#endif
44
45#ifndef OPEN_MAX
46# define OPEN_MAX 256
47#endif
48
49RCSID("$Id: bsd-closefrom.c,v 1.1 2004/08/15 08:41:00 djm Exp $");
49RCSID("$Id: bsd-closefrom.c,v 1.2 2005/11/10 08:29:13 dtucker Exp $");
50
51#ifndef lint
52static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $";
53#endif /* lint */
54
55/*
56 * Close all file descriptors greater than or equal to lowfd.
57 */

--- 4 unchanged lines hidden (view full) ---

62#if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID)
63 char fdpath[PATH_MAX], *endp;
64 struct dirent *dent;
65 DIR *dirp;
66 int len;
67
68 /* Check for a /proc/$$/fd directory. */
69 len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid());
50
51#ifndef lint
52static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $";
53#endif /* lint */
54
55/*
56 * Close all file descriptors greater than or equal to lowfd.
57 */

--- 4 unchanged lines hidden (view full) ---

62#if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID)
63 char fdpath[PATH_MAX], *endp;
64 struct dirent *dent;
65 DIR *dirp;
66 int len;
67
68 /* Check for a /proc/$$/fd directory. */
69 len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid());
70 if (len != -1 && len <= sizeof(fdpath) && (dirp = opendir(fdpath))) {
70 if (len >= 0 && (u_int)len <= sizeof(fdpath) && (dirp = opendir(fdpath))) {
71 while ((dent = readdir(dirp)) != NULL) {
72 fd = strtol(dent->d_name, &endp, 10);
73 if (dent->d_name != endp && *endp == '\0' &&
74 fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))
75 (void) close((int) fd);
76 }
77 (void) closedir(dirp);
78 } else

--- 22 unchanged lines hidden ---
71 while ((dent = readdir(dirp)) != NULL) {
72 fd = strtol(dent->d_name, &endp, 10);
73 if (dent->d_name != endp && *endp == '\0' &&
74 fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))
75 (void) close((int) fd);
76 }
77 (void) closedir(dirp);
78 } else

--- 22 unchanged lines hidden ---