Bug 79232 - [patch] WARNS6 clean libexec/comsat
Summary: [patch] WARNS6 clean libexec/comsat
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 6.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2005-03-25 17:20 UTC by Divacky Roman
Modified: 2022-10-17 12:39 UTC (History)
0 users

See Also:


Attachments
file.diff (6.76 KB, patch)
2005-03-25 17:20 UTC, Divacky Roman
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Divacky Roman 2005-03-25 17:20:01 UTC
this patch makes libexec/comsat WARN6 clean + checks some return codes of some
functions + some more fixes..

How-To-Repeat: apply this patch
Comment 1 Stefan Farfeleder freebsd_committer freebsd_triage 2005-03-26 08:23:05 UTC
> -	sprintf(buf, "%s/%.*s", _PATH_MAILDIR, (int)sizeof(utmp[0].ut_name),
> -	    name);
> +	sprintf(buf, "%s/%.*s", _PATH_MAILDIR, sizeof(utmp[0].ut_name), name);
>  	if (*file != '/') {
>  		sprintf(buf2, "%s/%.*s", _PATH_MAILDIR,
> -		    (int)sizeof(utmp[0].ut_name), file);
> +		      sizeof(utmp[0].ut_name), file);


> -	(void)snprintf(tty, sizeof(tty), "%s%.*s",
> -	    _PATH_DEV, (int)sizeof(utp->ut_line), utp->ut_line);
> +	snprintf(tty, sizeof(tty), "%s%.*s",
> +	      _PATH_DEV, sizeof(utp->ut_line), utp->ut_line);


> -		(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,
> +		    cr, utp->ut_name, sizeof(hostname), hostname,
>  		    folder ? cr : "", folder ? "to " : "", folder ? file : "",
>  		    cr, cr);

Those (int) casts are needed, removing them is an error.

Stefan
Comment 2 Divacky Roman 2005-05-12 15:07:58 UTC
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);
 }
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:58:51 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:39:04 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>