From a6eb0df2474c255c32b770ed16db04f0cfdd7ae0 Mon Sep 17 00:00:00 2001 From: Sheldon Hearn Date: Mon, 27 Mar 2000 11:49:36 +0000 Subject: [PATCH] Do not overwrite files when the -i option is specified! PR: 17476 Reported by: Jonathan Chen --- usr.bin/uudecode/uudecode.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c index 247e80212d1..1716c10e8dc 100644 --- a/usr.bin/uudecode/uudecode.c +++ b/usr.bin/uudecode/uudecode.c @@ -141,11 +141,11 @@ decode2(flag) struct passwd *pw; register int n; register char ch, first, *p; - int mode, n1; + int ignore, mode, n1; char buf[MAXPATHLEN]; char buffn[MAXPATHLEN]; /* file name buffer */ - + ignore = 0; /* search for header line */ do { if (!fgets(buf, sizeof(buf), stdin)) { @@ -197,9 +197,10 @@ decode2(flag) ; /* print to stdout */ else { - if (iflag && !access(buf, F_OK)) + if (iflag && !access(buf, F_OK)) { (void)fprintf(stderr, "not overwritten: %s\n", buf); - if (!freopen(buf, "w", stdout) || + ignore++; + } else if (!freopen(buf, "w", stdout) || fchmod(fileno(stdout), mode&0666)) { warn("%s: %s", buf, filename); return(1); @@ -224,6 +225,9 @@ decode2(flag) filename, buffn, 1 + ' ', 077 + ' ' + 1); \ return(1); \ } +#define PUTCHAR(c) \ +if (!ignore) \ + putchar(c) /* @@ -239,11 +243,11 @@ decode2(flag) OUT_OF_RANGE ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4; - putchar(ch); + PUTCHAR(ch); ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2; - putchar(ch); + PUTCHAR(ch); ch = DEC(p[2]) << 6 | DEC(p[3]); - putchar(ch); + PUTCHAR(ch); } else { @@ -251,7 +255,7 @@ decode2(flag) if (!(IS_DEC(*p) && IS_DEC(*(p + 1)))) OUT_OF_RANGE ch = DEC(p[0]) << 2 | DEC(p[1]) >> 4; - putchar(ch); + PUTCHAR(ch); } if (n >= 2) { if (!(IS_DEC(*(p + 1)) && @@ -259,14 +263,14 @@ decode2(flag) OUT_OF_RANGE ch = DEC(p[1]) << 4 | DEC(p[2]) >> 2; - putchar(ch); + PUTCHAR(ch); } if (n >= 3) { if (!(IS_DEC(*(p + 2)) && IS_DEC(*(p + 3)))) OUT_OF_RANGE ch = DEC(p[2]) << 6 | DEC(p[3]); - putchar(ch); + PUTCHAR(ch); } } }