=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/file/file.c,v retrieving revision 1.29 retrieving revision 1.30 diff -c -r1.29 -r1.30 *** src/usr.bin/file/file.c 2015/04/24 16:30:06 1.29 --- src/usr.bin/file/file.c 2015/04/24 16:47:32 1.30 *************** *** 1,4 **** ! /* $OpenBSD: file.c,v 1.29 2015/04/24 16:30:06 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: file.c,v 1.30 2015/04/24 16:47:32 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott *************** *** 91,98 **** int main(int argc, char **argv) { ! struct input_file *files = NULL; ! int nfiles, opt, i, width = 0; FILE *f; struct magic *m; char *home, *path; --- 91,98 ---- int main(int argc, char **argv) { ! struct input_file inf; ! int opt, i, width = 0; FILE *f; struct magic *m; char *home, *path; *************** *** 136,148 **** } else if (argc == 0) usage(); - nfiles = argc; - if (nfiles != 0) { - files = xcalloc(nfiles, sizeof *files); - for (i = 0; i < argc; i++) - open_file(&files[i], argv[i], &width); - } - home = getenv("HOME"); if (home == NULL || *home == '\0') { pw = getpwuid(getuid()); --- 136,141 ---- *************** *** 167,192 **** if (f == NULL) err(1, "%s", path); - if (geteuid() == 0) { - pw = getpwnam(FILE_USER); - if (pw == NULL) - errx(1, "unknown user %s", FILE_USER); - if (setgroups(1, &pw->pw_gid) != 0) - err(1, "setgroups"); - if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) != 0) - err(1, "setresgid"); - if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) != 0) - err(1, "setresuid"); - } - m = magic_load(f, path, cflag || Wflag); if (cflag) { magic_dump(m); exit(0); } ! for (i = 0; i < nfiles; i++) ! test_file(m, &files[i], width); exit(0); } --- 160,176 ---- if (f == NULL) err(1, "%s", path); m = magic_load(f, path, cflag || Wflag); if (cflag) { magic_dump(m); exit(0); } ! for (i = 0; i < argc; i++) { ! memset(&inf, 0, sizeof inf); ! open_file(&inf, argv[i], &width); ! test_file(m, &inf, width); ! } exit(0); } *************** *** 282,288 **** } if (got == 0) break; ! next = (char*)next + got; left -= got; } --- 266,272 ---- } if (got == 0) break; ! next = (char *)next + got; left -= got; } *************** *** 508,517 **** printf("%s\n", inf->result); else printf("%-*s %s\n", width, inf->label, inf->result); if (inf->mapped && inf->base != NULL) munmap(inf->base, inf->size); inf->base = NULL; ! free(inf->result); } --- 492,505 ---- printf("%s\n", inf->result); else printf("%-*s %s\n", width, inf->label, inf->result); + free(inf->result); if (inf->mapped && inf->base != NULL) munmap(inf->base, inf->size); inf->base = NULL; ! if (inf->fd != -1) ! close(inf->fd); ! free((void *)inf->label); ! free((void *)inf->path); }