Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Jul 2001 11:44:36 -0400 (EDT)
From:      Mike Barcroft <mike@q9media.com>
To:        Mike Heffner <mheffner@novacoxmail.com>
Cc:        audit@FreeBSD.org, Mike Heffner <mheffner@vt.edu>
Subject:   Re: src/bin/chio patch
Message-ID:  <200107031544.f63FiaV07250@coffee.q9media.com>

next in thread | raw e-mail | index | archive | help
Mike Barcroft <mike@q9media.com> writes:
> Mike Barcroft <mike@q9media.com> writes:
> > -		strncpy(csvr.csvr_voltag.cv_volid, argv[2],
> > +		(void) memcpy(csvr.csvr_voltag.cv_volid, argv[2],
> >  		       sizeof(csvr.csvr_voltag.cv_volid));
> > +		csvr.csvr_voltag.cv_volid[strlen(argv[2]) + 1] = '\0';
>
> Hmm..  what was I thinking with this?  It's probably better just
> to use a cast.  Also the NUL char is off by one byte and assumes
> that strlen(argv[2]) < sizeof(csvr.csvr_voltag.cv_volid).
>
> I should go to sleep.  I'll fix this in the morning.

I've corrected this in the patch at the end of this message and
also at: http://testbed.q9media.com/freebsd/chio.20010704.patch

Best regards,
Mike Barcroft

-----------------------------------------------------------------------

chio.20010704.patch

o Attempt to silence warnings generated on an Alpha.
o Set WARNS?=2


Index: chio/Makefile
===================================================================
RCS file: /home/ncvs/src/bin/chio/Makefile,v
retrieving revision 1.9
diff -u -r1.9 Makefile
--- chio/Makefile	2001/07/03 03:34:42	1.9
+++ chio/Makefile	2001/07/03 15:27:40
@@ -2,6 +2,7 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
 
 PROG=	chio
+WARNS?=	2
 SRCS=	chio.c
 
 .include <bsd.prog.mk>
Index: chio/chio.c
===================================================================
RCS file: /home/ncvs/src/bin/chio/chio.c,v
retrieving revision 1.18
diff -u -r1.18 chio.c
--- chio/chio.c	2001/07/03 03:22:49	1.18
+++ chio/chio.c	2001/07/03 15:27:41
@@ -63,10 +63,11 @@
 static	const char * element_type_name __P((int et));
 static	int parse_special __P((char *));
 static	int is_special __P((char *));
-static	const char *bits_to_string __P((int, const char *));
+static	const char *bits_to_string __P((ces_status_flags, const char *));
 
 static	void find_element __P((char *, u_int16_t *, u_int16_t *));
-static	struct changer_element_status *get_element_status __P((u_int16_t, u_int16_t));
+static	struct changer_element_status *get_element_status
+	    __P((unsigned int, unsigned int));
 
 static	int do_move __P((const char *, int, char **));
 static	int do_exchange __P((const char *, int, char **));
@@ -689,7 +690,7 @@
 		/* Allocate storage for the status structures. */
 		cesr.cesr_element_status =
 		  (struct changer_element_status *) 
-		  calloc(count, sizeof(struct changer_element_status));
+		  calloc((size_t)count, sizeof(struct changer_element_status));
 		
 		if (!cesr.cesr_element_status)
 			errx(1, "can't allocate status storage");
@@ -845,8 +846,8 @@
 			goto usage;
 		}
 
-		strncpy(csvr.csvr_voltag.cv_volid, argv[2],
-		       sizeof(csvr.csvr_voltag.cv_volid));
+		strlcpy((char *)csvr.csvr_voltag.cv_volid, argv[2],
+		    sizeof(csvr.csvr_voltag.cv_volid));
 
 		if (argc == 4) {
 			csvr.csvr_voltag.cv_serial = atol(argv[3]);
@@ -944,7 +945,7 @@
 
 static const char *
 bits_to_string(v, cp)
-	int v;
+	ces_status_flags v;
 	const char *cp;
 {
 	const char *np;
@@ -1006,7 +1007,8 @@
 	}
 	++argv; --argc;
 
-	ces = get_element_status(type, element);	/* Get the status */
+	/* Get the status */
+	ces = get_element_status((unsigned int)type, (unsigned int)element);
 
 	if (NULL == ces)
 		errx(1, "%s: null element status pointer", cname);
@@ -1042,22 +1044,22 @@
  */
 static struct changer_element_status *
 get_element_status(type, element)
-	u_int16_t	type;
-	u_int16_t	element;
+	unsigned int	type;
+	unsigned int	element;
 {
 	struct changer_element_status_request cesr;
 	struct changer_element_status *ces;
 	
 	ces = (struct changer_element_status *)
-	    calloc(1, sizeof(struct changer_element_status));
+	    calloc((size_t)1, sizeof(struct changer_element_status));
 
 	if (NULL == ces)
 		errx(1, "can't allocate status storage");
 
 	(void)memset(&cesr, 0, sizeof(cesr));
 
-	cesr.cesr_element_type = type;
-	cesr.cesr_element_base = element;
+	cesr.cesr_element_type = (u_int16_t)type;
+	cesr.cesr_element_base = (u_int16_t)element;
 	cesr.cesr_element_count = 1;		/* Only this one element */
 	cesr.cesr_flags |= CESR_VOLTAGS;	/* Grab voltags as well */
 	cesr.cesr_element_status = ces;
@@ -1088,7 +1090,8 @@
 	struct changer_params cp;
 	struct changer_element_status_request cesr;
 	struct changer_element_status *ch_ces, *ces;
-	int elem, total_elem, found = 0;
+	int found = 0;
+	size_t elem, total_elem;
 
 	/*
 	 * Get the changer parameters, we're interested in the counts
@@ -1185,7 +1188,8 @@
 			continue;
 
 		/* Check to see if it is our target */
-		if (strcasecmp(voltag, ces->ces_pvoltag.cv_volid) == 0) {
+		if (strcasecmp(voltag,
+		    (const char *)ces->ces_pvoltag.cv_volid) == 0) {
 			*et = ces->ces_type;
 			*eu = ces->ces_addr;
 			++found;

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200107031544.f63FiaV07250>