=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/strip/Attic/strip.c,v retrieving revision 1.16 retrieving revision 1.17 diff -c -r1.16 -r1.17 *** src/usr.bin/strip/Attic/strip.c 2002/02/16 21:27:53 1.16 --- src/usr.bin/strip/Attic/strip.c 2002/08/21 15:51:08 1.17 *************** *** 1,4 **** ! /* $OpenBSD: strip.c,v 1.16 2002/02/16 21:27:53 millert Exp $ */ /* * Copyright (c) 1988 Regents of the University of California. --- 1,4 ---- ! /* $OpenBSD: strip.c,v 1.17 2002/08/21 15:51:08 espie Exp $ */ /* * Copyright (c) 1988 Regents of the University of California. *************** *** 41,47 **** #ifndef lint /*static char sccsid[] = "from: @(#)strip.c 5.8 (Berkeley) 11/6/91";*/ ! static char rcsid[] = "$OpenBSD: strip.c,v 1.16 2002/02/16 21:27:53 millert Exp $"; #endif /* not lint */ #include --- 41,47 ---- #ifndef lint /*static char sccsid[] = "from: @(#)strip.c 5.8 (Berkeley) 11/6/91";*/ ! static char rcsid[] = "$OpenBSD: strip.c,v 1.17 2002/08/21 15:51:08 espie Exp $"; #endif /* not lint */ #include *************** *** 69,76 **** #define strx n_un.n_strx ! int s_stab(const char *, int, EXEC *, struct stat *); ! int s_sym(const char *, int, EXEC *, struct stat *); void usage(void); int xflag = 0; --- 69,76 ---- #define strx n_un.n_strx ! int s_stab(const char *, int, EXEC *, struct stat *, off_t *); ! int s_sym(const char *, int, EXEC *, struct stat *, off_t *); void usage(void); int xflag = 0; *************** *** 83,91 **** int fd; EXEC *ep; struct stat sb; ! int (*sfcn)(const char *, int, EXEC *, struct stat *); int ch, errors; char *fn; sfcn = s_sym; while ((ch = getopt(argc, argv, "dx")) != -1) --- 83,92 ---- int fd; EXEC *ep; struct stat sb; ! int (*sfcn)(const char *, int, EXEC *, struct stat *, off_t *); int ch, errors; char *fn; + off_t newsize; sfcn = s_sym; while ((ch = getopt(argc, argv, "dx")) != -1) *************** *** 131,139 **** for dealing with data in memory, and a second time for out */ fix_header_order(ep); ! errors |= sfcn(fn, fd, ep, &sb); fix_header_order(ep); munmap((caddr_t)ep, sb.st_size); if (close(fd)) { ERROR(errno); } --- 132,145 ---- for dealing with data in memory, and a second time for out */ fix_header_order(ep); ! newsize = 0; ! errors |= sfcn(fn, fd, ep, &sb, &newsize); fix_header_order(ep); munmap((caddr_t)ep, sb.st_size); + if (newsize && ftruncate(fd, newsize)) { + warn("%s", fn); + errors = 1; + } if (close(fd)) { ERROR(errno); } *************** *** 143,153 **** } int ! s_sym(fn, fd, ep, sp) const char *fn; int fd; EXEC *ep; struct stat *sp; { char *neweof; #if 0 --- 149,160 ---- } int ! s_sym(fn, fd, ep, sp, sz) const char *fn; int fd; EXEC *ep; struct stat *sp; + off_t *sz; { char *neweof; #if 0 *************** *** 203,222 **** ep->a_syms = ep->a_trsize = ep->a_drsize = 0; /* Truncate the file. */ ! if (ftruncate(fd, neweof - (char *)ep)) { ! warn("%s", fn); ! return 1; ! } return 0; } int ! s_stab(fn, fd, ep, sp) const char *fn; int fd; EXEC *ep; struct stat *sp; { int cnt, len; char *nstr, *nstrbase, *p, *strbase; --- 210,227 ---- ep->a_syms = ep->a_trsize = ep->a_drsize = 0; /* Truncate the file. */ ! *sz = neweof - (char *)ep; return 0; } int ! s_stab(fn, fd, ep, sp, sz) const char *fn; int fd; EXEC *ep; struct stat *sp; + off_t *sz; { int cnt, len; char *nstr, *nstrbase, *p, *strbase; *************** *** 276,281 **** --- 281,290 ---- continue; } len = strlen(p) + 1; + if (N_STROFF(*ep) + sym->strx + len > sp->st_size) { + warnx("%s: bad symbol table", fn); + return 1; + } bcopy(p, nstr, len); nstr += len; fix_nlist_order(nsym++, mid); *************** *** 297,306 **** free(nstrbase); /* Truncate to the current length. */ ! if (ftruncate(fd, (char *)nsym + len - (char *)ep)) { ! warn("%s", fn); ! return 1; ! } return 0; } --- 306,312 ---- free(nstrbase); /* Truncate to the current length. */ ! *sz = (char *)nsym + len - (char *)ep; return 0; }