bin/79232: WARNS6 clean libexec/comsat

Divacky Roman xdivac02 at stud.fit.vutbr.cz
Thu May 12 14:10:06 GMT 2005


The following reply was made to PR bin/79232; it has been noted by GNATS.

From: Divacky Roman <xdivac02 at stud.fit.vutbr.cz>
To: bug-followup at FreeBSD.org
Cc:  
Subject: Re: bin/79232: WARNS6 clean libexec/comsat
Date: Thu, 12 May 2005 16:07:58 +0200

 new patch:
 
 ? comsat.patch
 Index: comsat.c
 ===================================================================
 RCS file: /home/ncvs/src/libexec/comsat/comsat.c,v
 retrieving revision 1.17
 diff -u -r1.17 comsat.c
 --- comsat.c	14 Feb 2005 17:42:56 -0000	1.17
 +++ comsat.c	12 May 2005 14:06:21 -0000
 @@ -85,7 +85,7 @@
  void reapchildren(int);
  
  int
 -main(int argc, char *argv[])
 +main(int __unused argc, char __unused *argv[])
  {
  	struct sockaddr_in from;
  	socklen_t fromlen;
 @@ -99,20 +99,21 @@
  	openlog("comsat", LOG_PID, LOG_DAEMON);
  	if (chdir(_PATH_MAILDIR)) {
  		syslog(LOG_ERR, "chdir: %s: %m", _PATH_MAILDIR);
 -		(void) recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
 +		recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
  		exit(1);
  	}
  	if ((uf = open(_PATH_UTMP, O_RDONLY, 0)) < 0) {
  		syslog(LOG_ERR, "open: %s: %m", _PATH_UTMP);
 -		(void) recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
 +		recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
  		exit(1);
  	}
 -	(void)time(&lastmsgtime);
 -	(void)gethostname(hostname, sizeof(hostname));
 +	time(&lastmsgtime);
 +	if (gethostname(hostname, sizeof(hostname)) == -1)
 +	   err(1, "gehostname");
  	onalrm(0);
 -	(void)signal(SIGALRM, onalrm);
 -	(void)signal(SIGTTOU, SIG_IGN);
 -	(void)signal(SIGCHLD, reapchildren);
 +	signal(SIGALRM, onalrm);
 +	signal(SIGTTOU, SIG_IGN);
 +	signal(SIGCHLD, reapchildren);
  	for (;;) {
  		cc = recv(0, msgbuf, sizeof(msgbuf) - 1, 0);
  		if (cc <= 0) {
 @@ -125,29 +126,30 @@
  			continue;
  		sigblock(sigmask(SIGALRM));
  		msgbuf[cc] = '\0';
 -		(void)time(&lastmsgtime);
 +		time(&lastmsgtime);
  		mailfor(msgbuf);
  		sigsetmask(0L);
  	}
  }
  
  void
 -reapchildren(int signo)
 +reapchildren(int __unused signo)
  {
  	while (wait3(NULL, WNOHANG, NULL) > 0);
  }
  
  void
 -onalrm(int signo)
 +onalrm(int __unused signo)
  {
 -	static u_int utmpsize;		/* last malloced size for utmp */
 -	static u_int utmpmtime;		/* last modification time for utmp */
 +	static size_t utmpsize;		/* last malloced size for utmp */
 +	static time_t utmpmtime;	/* last modification time for utmp */
  	struct stat statbf;
  
  	if (time(NULL) - lastmsgtime >= MAXIDLE)
  		exit(0);
 -	(void)alarm((u_int)15);
 -	(void)fstat(uf, &statbf);
 +	alarm(15);
 +	if (fstat(uf, &statbf) == -1)
 +	   err(1, "fstat");
  	if (statbf.st_mtime > utmpmtime) {
  		utmpmtime = statbf.st_mtime;
  		if (statbf.st_size > utmpsize) {
 @@ -157,7 +159,8 @@
  				exit(1);
  			}
  		}
 -		(void)lseek(uf, (off_t)0, SEEK_SET);
 +		if (lseek(uf, 0, SEEK_SET) == -1)
 +		   err(1, "lseek");
  		nutmp = read(uf, utmp, (size_t)statbf.st_size)/sizeof(struct utmp);
  	}
  }
 @@ -194,7 +197,7 @@
  			notify(utp, file, offset, folder);
  }
  
 -static char *cr;
 +const char *cr = "\n";
  
  void
  notify(struct utmp *utp, char file[], off_t offset, int folder)
 @@ -204,7 +207,7 @@
  	struct termios tio;
  	char tty[20], name[sizeof(utmp[0].ut_name) + 1];
  
 -	(void)snprintf(tty, sizeof(tty), "%s%.*s",
 +	snprintf(tty, sizeof(tty), "%s%.*s",
  	    _PATH_DEV, (int)sizeof(utp->ut_line), utp->ut_line);
  	if (strchr(tty + sizeof(_PATH_DEV) - 1, '/')) {
  		/* A slash is an attempt to break security... */
 @@ -218,20 +221,20 @@
  	dsyslog(LOG_DEBUG, "notify %s on %s\n", utp->ut_name, tty);
  	if (fork())
  		return;
 -	(void)signal(SIGALRM, SIG_DFL);
 -	(void)alarm((u_int)30);
 +	signal(SIGALRM, SIG_DFL);
 +	alarm(30);
  	if ((tp = fopen(tty, "w")) == NULL) {
  		dsyslog(LOG_ERR, "%s: %s", tty, strerror(errno));
  		_exit(1);
  	}
 -	(void)tcgetattr(fileno(tp), &tio);
 -	cr = ((tio.c_oflag & (OPOST|ONLCR)) == (OPOST|ONLCR)) ?  "\n" : "\n\r";
 +	if (tcgetattr(fileno(tp), &tio) == -1)
 +	   err(1, "tcgetattr");
  	(void)strncpy(name, utp->ut_name, sizeof(utp->ut_name));
  	name[sizeof(name) - 1] = '\0';
  	switch (stb.st_mode & (S_IXUSR | S_IXGRP)) {
  	case S_IXUSR:
  	case (S_IXUSR | S_IXGRP):
 -		(void)fprintf(tp, 
 +		fprintf(tp, 
  		    "%s\007New mail for %s@%.*s\007 has arrived%s%s%s:%s----%s",
  		    cr, name, (int)sizeof(hostname), hostname,
  		    folder ? cr : "", folder ? "to " : "", folder ? file : "",
 @@ -239,15 +242,15 @@
  		jkfprintf(tp, name, file, offset);
  		break;
  	case S_IXGRP:
 -		(void)fprintf(tp, "\007");
 -		(void)fflush(tp);      
 -		(void)sleep(1);
 -		(void)fprintf(tp, "\007");
 +		fprintf(tp, "\007");
 +		fflush(tp);      
 +		sleep(1);
 +		fprintf(tp, "\007");
  		break;
  	default:
  		break;
  	}	
 -	(void)fclose(tp);
 +	fclose(tp);
  	_exit(0);
  }
  
 @@ -258,16 +261,18 @@
  	FILE *fi;
  	int linecnt, charcnt, inheader;
  	struct passwd *p;
 -	unsigned char line[BUFSIZ];
 +	char line[BUFSIZ];
  
  	/* Set effective uid to user in case mail drop is on nfs */
  	if ((p = getpwnam(user)) != NULL)
 -		(void) setuid(p->pw_uid);
 +		if (setuid(p->pw_uid) == -1)
 +		   err(1, "setuid");
  
  	if ((fi = fopen(file, "r")) == NULL)
  		return;
  
 -	(void)fseeko(fi, offset, SEEK_CUR);
 +	if (fseeko(fi, offset, SEEK_CUR) == -1)
 +	   err(1, "fseeko");
  	/*
  	 * Print the first 7 lines or 560 characters of the new mail
  	 * (whichever comes first).  Skip header crap other than
 @@ -288,12 +293,12 @@
  				continue;
  		}
  		if (linecnt <= 0 || charcnt <= 0) {
 -			(void)fprintf(tp, "...more...%s", cr);
 -			(void)fclose(fi);
 +			fprintf(tp, "...more...%s", cr);
 +			fclose(fi);
  			return;
  		}
  		/* strip weird stuff so can't trojan horse stupid terminals */
 -		for (cp = line; (ch = *cp) && ch != '\n'; ++cp, --charcnt) {
 +		for (cp = (unsigned char *)line; (ch = *cp) && ch != '\n'; ++cp, --charcnt) {
  			/* disable upper controls and enable all other
  			   8bit codes due to lack of locale knowledge
  			 */
 @@ -303,18 +308,18 @@
  			   ) {
  				if (ch & 0x80) {
  					ch &= ~0x80;
 -					(void)fputs("M-", tp);
 +					fputs("M-", tp);
  				}
  				if (iscntrl(ch)) {
  					ch ^= 0x40;
 -					(void)fputc('^', tp);
 +					fputc('^', tp);
  				}
  			}
 -			(void)fputc(ch, tp);
 +			fputc(ch, tp);
  		}
 -		(void)fputs(cr, tp);
 +		fputs(cr, tp);
  		--linecnt;
  	}
 -	(void)fprintf(tp, "----%s\n", cr);
 -	(void)fclose(fi);
 +	fprintf(tp, "----%s\n", cr);
 +	fclose(fi);
  }
 


More information about the freebsd-bugs mailing list