summaryrefslogtreecommitdiffstats
path: root/usr.bin/uudecode
diff options
context:
space:
mode:
authorsheldonh <sheldonh@FreeBSD.org>2000-03-27 11:49:36 +0000
committersheldonh <sheldonh@FreeBSD.org>2000-03-27 11:49:36 +0000
commit5f2d618ecb2e12499e6cd21212bc033a32ae3471 (patch)
tree69d715a798ec4cc452d1d0926b5b68c5dc769ed9 /usr.bin/uudecode
parente01cfe70065d8ae8666432faaf7e1dfcb7e120a3 (diff)
downloadFreeBSD-src-5f2d618ecb2e12499e6cd21212bc033a32ae3471.zip
FreeBSD-src-5f2d618ecb2e12499e6cd21212bc033a32ae3471.tar.gz
Do not overwrite files when the -i option is specified!
PR: 17476 Reported by: Jonathan Chen <jon@spock.org>
Diffstat (limited to 'usr.bin/uudecode')
-rw-r--r--usr.bin/uudecode/uudecode.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c
index 247e802..1716c10 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);
}
}
}
OpenPOWER on IntegriCloud