Subject: bin/8215: mount_portal/pt_filter.c assumes size_t is signed int
To: None <gnats-bugs@gnats.netbsd.org>
From: None <seebs@plethora.net>
List: netbsd-bugs
Date: 08/16/1999 21:11:56
>Number:         8215
>Category:       bin
>Synopsis:       pt_filter.c uses %d to print out result of strlen
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 16 20:50:02 1999
>Last-Modified:
>Originator:     Seebs
>Organization:
>Release:        Aug 16 1999
>Environment:
System: NetBSD gandalf.plethora.net 1.4J NetBSD 1.4J (GANDALF) #0: Mon Aug 16 14:51:06 CDT 1999 seebs@gandalf.plethora.net:/usr/src/sys/arch/alpha/compile/GANDALF alpha


>Description:
	pt_filter.c fails to compile because -Wall catches two errors
>How-To-Repeat:
	'make build'
>Fix:

My suggestion: size_t is some unsigned type, and canonically (although maybe
not here) no larger than 'unsigned long', so we cast to that type and print
it.  'size_t' should not be bigger than long, and if it is, well, 4GB strings
are rare, and we might as well write the canonical ANSI code, even if it
may eventually fail on an oddly-designed system.

*** pt_filter.c.orig	Mon Aug 16 22:40:18 1999
--- pt_filter.c	Mon Aug 16 22:41:02 1999
***************
*** 144,151 ****
  	fill_cmd(v + 2, path, cmd, FILTER_CMD_SIZE);
  	if (strlen(cmd) >= FILTER_CMD_SIZE) {
  		syslog(LOG_WARNING,
! 		    "Warning:  potential overflow on string!  Length was %d\n",
! 		    strlen(cmd));
  		return -1;
  	}
  #ifdef DEBUG
--- 144,151 ----
  	fill_cmd(v + 2, path, cmd, FILTER_CMD_SIZE);
  	if (strlen(cmd) >= FILTER_CMD_SIZE) {
  		syslog(LOG_WARNING,
! 		    "Warning:  potential overflow on string!  Length was %lu\n",
! 		    (unsigned long) strlen(cmd));
  		return -1;
  	}
  #ifdef DEBUG
***************
*** 203,210 ****
  	fill_cmd(v + 2, path, cmd, FILTER_CMD_SIZE);
  	if (strlen(cmd) >= FILTER_CMD_SIZE) {
  		syslog(LOG_WARNING,
! 		    "Warning:  potential overflow on string!  Length was %d\n",
! 		    strlen(cmd));
  		return -1;
  	}
  	fp = popen(cmd, "w");
--- 203,210 ----
  	fill_cmd(v + 2, path, cmd, FILTER_CMD_SIZE);
  	if (strlen(cmd) >= FILTER_CMD_SIZE) {
  		syslog(LOG_WARNING,
! 		    "Warning:  potential overflow on string!  Length was %lu\n",
! 		    (unsigned long) strlen(cmd));
  		return -1;
  	}
  	fp = popen(cmd, "w");
>Audit-Trail:
>Unformatted: