Newsgroup: comp.bugs.4bsd


Article 993 of comp.bugs.4bsd:
Path: icdoc!mvax.cc.ic.ac.uk!cc.ic.ac.uk!dds
>From: dds@cc.ic.ac.uk (Diomidis Spinellis)
Newsgroups: comp.bugs.4bsd
Subject: Uuencode / uudecode do not check for failed writes
Keywords: uuencode uudecode
Message-ID: <1990May9.203433.19501@cc.ic.ac.uk>
Date: 9 May 90 20:34:33 GMT
Sender: news@cc.ic.ac.uk (USENET News System)
Reply-To: dds@cc.ic.ac.uk (Diomidis Spinellis)
Organization: Imperial College Computer Center, London, UK
Lines: 206
Content-Length: 4487
Index:  usr.bin/uucp/uuencode.c usr.bin/uucp/uudecode.c 4.3BSD

Description:
        Uuencode and uudecode do not check the return value of the functions
	used to create the output file.  As a result when the output device
	becomes full or disk quota are exceeded the program terminates 
	without an error indication.

Repeat-By:
	Run uuencode vmunix </vmunix >file with disk quota set to 100k.
	Then run uudecode <file with the same disk quota.

Fix:
	Change usr.bin/uucp/uuencode.c and usr.bin/uucp/uudecode.c by 
	applying the following patch:

*** uudecode.c.orig	Wed May  9 21:14:30 1990
--- uudecode.c	Wed May  9 21:21:30 1990
***************
*** 33,44 ****
  /* single character decode */
  #define DEC(c)	(((c) - ' ') & 077)
  
  main(argc, argv)
  char **argv;
  {
  	FILE *in, *out;
  	int mode;
- 	char dest[128];
  	char buf[80];
  
  	/* optional input arg */
--- 33,51 ----
  /* single character decode */
  #define DEC(c)	(((c) - ' ') & 077)
  
+ static char dest[128];
+ 
+ #define eputc(c, f) \
+ 	if (putc(c, f) == EOF) { \
+ 		perror(dest); \
+ 		exit(1); \
+ 	}
+ 
  main(argc, argv)
  char **argv;
  {
  	FILE *in, *out;
  	int mode;
  	char buf[80];
  
  	/* optional input arg */
***************
*** 52,58 ****
  		in = stdin;
  
  	if (argc != 1) {
! 		printf("Usage: uudecode [infile]\n");
  		exit(2);
  	}
  
--- 59,65 ----
  		in = stdin;
  
  	if (argc != 1) {
! 		fprintf(stderr, "Usage: uudecode [infile]\n");
  		exit(2);
  	}
  
***************
*** 105,110 ****
--- 112,121 ----
  		fprintf(stderr, "No end line\n");
  		exit(5);
  	}
+ 	if (fclose(out) == EOF) {
+ 		perror(dest);
+ 		exit(1);
+ 	}
  	exit(0);
  }
  
***************
*** 154,162 ****
  	c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
  	c3 = DEC(p[2]) << 6 | DEC(p[3]);
  	if (n >= 1)
! 		putc(c1, f);
  	if (n >= 2)
! 		putc(c2, f);
  	if (n >= 3)
! 		putc(c3, f);
  }
--- 165,173 ----
  	c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
  	c3 = DEC(p[2]) << 6 | DEC(p[3]);
  	if (n >= 1)
! 		eputc(c1, f);
  	if (n >= 2)
! 		eputc(c2, f);
  	if (n >= 3)
! 		eputc(c3, f);
  }
*** uuencode.c.orig	Wed May  9 21:14:31 1990
--- uuencode.c	Wed May  9 21:16:31 1990
***************
*** 31,36 ****
--- 31,42 ----
  /* ENC is the basic 1 character encoding function to make a char printing */
  #define ENC(c) ((c) ? ((c) & 077) + ' ': '`')
  
+ #define eputc(c, f) \
+ 	if (putc(c, f) == EOF) { \
+ 		perror("write"); \
+ 		exit(1); \
+ 	}
+ 
  main(argc, argv)
  char **argv;
  {
***************
*** 58,68 ****
  		mode = 0666 & ~umask(0666);
  	else
  		mode = sbuf.st_mode & 0777;
! 	printf("begin %o %s\n", mode, argv[1]);
  
  	encode(in, stdout);
  
! 	printf("end\n");
  	exit(0);
  }
  
--- 64,84 ----
  		mode = 0666 & ~umask(0666);
  	else
  		mode = sbuf.st_mode & 0777;
! 	if (printf("begin %o %s\n", mode, argv[1]) == EOF) {
! 		perror("write");
! 		exit(1);
! 	}
  
  	encode(in, stdout);
  
! 	if (printf("end\n") == EOF) {
! 		perror("write");
! 		exit(1);
! 	}
! 	if (fclose(stdout) == EOF) {
! 		perror("write");
! 		exit(1);
! 	}
  	exit(0);
  }
  
***************
*** 79,90 ****
  	for (;;) {
  		/* 1 (up to) 45 character line */
  		n = fread(buf, 1, 45, in);
! 		putc(ENC(n), out);
  
  		for (i=0; i<n; i += 3)
  			outdec(&buf[i], out);
  
! 		putc('\n', out);
  		if (n <= 0)
  			break;
  	}
--- 95,106 ----
  	for (;;) {
  		/* 1 (up to) 45 character line */
  		n = fread(buf, 1, 45, in);
! 		eputc(ENC(n), out);
  
  		for (i=0; i<n; i += 3)
  			outdec(&buf[i], out);
  
! 		eputc('\n', out);
  		if (n <= 0)
  			break;
  	}
***************
*** 103,110 ****
  	c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;
  	c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
  	c4 = p[2] & 077;
! 	putc(ENC(c1), f);
! 	putc(ENC(c2), f);
! 	putc(ENC(c3), f);
! 	putc(ENC(c4), f);
  }
--- 119,126 ----
  	c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;
  	c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
  	c4 = p[2] & 077;
! 	eputc(ENC(c1), f);
! 	eputc(ENC(c2), f);
! 	eputc(ENC(c3), f);
! 	eputc(ENC(c4), f);
  }
--
Diomidis Spinellis                  Internet:                 dds@cc.ic.ac.uk
Department of Computing             UUCP:                    ...!ukc!iccc!dds
Imperial College                    JANET:                    dds@uk.ac.ic.cc
London SW7 2BZ                      #include "/dev/tty"




Newsgroup comp.bugs.4bsd contents
Newsgroup list
Diomidis Spinellis home page

Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.