if ((sudo_mode & MODE_SHELL)) {
char **dst, **src = NewArgv;
- NewArgv = (char **) malloc (sizeof(char *) * (++NewArgc));
+ NewArgv = (char **) malloc (sizeof(char *) * (++NewArgc + 1));
if (NewArgv == NULL) {
perror("malloc");
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
}
/* copy the args from Argv */
- dst = NewArgv + 1;
- *dst = (char *) NULL;
- while (*src) {
- *dst++ = *src++;
- }
+ for (dst = NewArgv + 1; (*dst = *src) != NULL; ++src, ++dst)
+ ;
}
rtn = check_sudoers(); /* check mode/owner on _PATH_SUDO_SUDOERS */
#else
exit(0);
#endif /* PROFILING */
- perror(cmnd); /* exec failed! */
+ /*
+ * If we got here then the exec() failed...
+ */
+ (void) fprintf(stderr, "%s: ", Argv[0]);
+ perror(cmnd);
exit(-1);
break;
*
* load_cmnd()
*
- * This function sets the cmnd global variable based on Argv
+ * This function sets the cmnd global variable
*/
static void load_cmnd(sudo_mode)
static int check_sudoers()
{
struct stat statbuf;
- int fd;
+ int fd = -1;
char c;
int rtn = ALL_SYSTEMS_GO;
}
}
- (void) close(fd);
+ if (fd != -1)
+ (void) close(fd);
set_perms(PERM_ROOT);
set_perms(PERM_USER);