NetBSD Problem Report #42143
From www@NetBSD.org Thu Oct 1 06:49:14 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by www.NetBSD.org (Postfix) with ESMTP id 1F89C63C378
for <gnats-bugs@gnats.netbsd.org>; Thu, 1 Oct 2009 06:49:14 +0000 (UTC)
Message-Id: <20091001064913.84E1063B8B6@www.NetBSD.org>
Date: Thu, 1 Oct 2009 06:49:13 +0000 (UTC)
From: yasu1224@ics.nara-wu.ac.jp
Reply-To: yasu1224@ics.nara-wu.ac.jp
To: gnats-bugs@NetBSD.org
Subject: A transformation without the cast
X-Send-Pr-Version: www-1.0
>Number: 42143
>Category: bin
>Synopsis: A transformation without the cast
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 01 06:50:00 +0000 2009
>Closed-Date: Sun Oct 18 15:26:11 +0000 2009
>Last-Modified: Sun Oct 18 15:26:11 +0000 2009
>Originator: Yamanishi Yasuyo
>Release: i386
>Organization:
Nara Women's University
>Environment:
NetBSD ayanamirei 4.0 NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:20:10 PST 2007 builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/GENERIC i386
>Description:
Implicit cast from long to int may cause an integer overflow
especially with 64-bit CPU. A wrapper function can fix it.
>How-To-Repeat:
>Fix:
--- kill2.c 2009-09-30 23:58:53.000000000 +0900
+++ kill.c 2009-09-25 23:00:33.000000000 +0900
@@ -64,6 +64,7 @@
static void printsignals(FILE *);
static int signame_to_signum(char *);
static void usage(void);
+static strto_int(const char*,char**,int);
int main(int, char *[]);
int
@@ -87,7 +88,7 @@
if (argc == 1) {
if (isdigit((unsigned char)**argv) == 0)
usage();
- numsig = strtol(*argv, &ep, 10);
+ numsig = strto_int(*argv, &ep, 10);
if (*ep != '\0') {
errx(EXIT_FAILURE, "illegal signal number: %s",
*argv);
@@ -122,7 +123,7 @@
if ((numsig = signame_to_signum(sn)) < 0)
nosig(sn);
} else if (isdigit((unsigned char)*sn)) {
- numsig = strtol(sn, &ep, 10);
+ numsig = strto_int(sn, &ep, 10);
if (*ep) {
errx(EXIT_FAILURE, "illegal signal number: %s",
sn);
@@ -151,7 +152,7 @@
} else
#endif
{
- pid = strtol(*argv, &ep, 10);
+ pid = strto_int(*argv, &ep, 10);
if (!**argv || *ep) {
warnx("illegal process id: %s", *argv);
errors = 1;
@@ -240,4 +241,23 @@
getprogname(), getprogname(), getprogname(), getprogname());
exit(1);
/* NOTREACHED */
-}
\ No newline at end of file
+}
+
+static int
+strto_int(const char * nptr ,char ** end ,int base)
+{
+ int tmp;
+ long sig,check;
+
+ sig = strtol(nptr, end, base);
+ tmp = (int) sig;
+ check = (long) tmp;
+
+ if( check != sig ){
+ warnx("Overflow occered in the cast (from long to int) .");
+ }
+
+ return tmp;
+}
+
+
>Release-Note:
>Audit-Trail:
From: "S.P.Zeidler" <spz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/42143 CVS commit: src/bin/kill
Date: Thu, 1 Oct 2009 09:24:39 +0000
Module Name: src
Committed By: spz
Date: Thu Oct 1 09:24:38 UTC 2009
Modified Files:
src/bin/kill: kill.c
Log Message:
Make sure that numerical signals and pids are in range for their types.
Fixes PR bin/42143
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/bin/kill/kill.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->pending-pullups
State-Changed-By: spz@NetBSD.org
State-Changed-When: Thu, 01 Oct 2009 09:39:03 +0000
State-Changed-Why:
Good catch :) range checks have been added (if in a bit terser way than
suggested). Pullup requests to -4 and -5 have been sent.
From: Soren Jacobsen <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/42143 CVS commit: [netbsd-5] src/bin/kill
Date: Sat, 3 Oct 2009 23:20:05 +0000
Module Name: src
Committed By: snj
Date: Sat Oct 3 23:20:05 UTC 2009
Modified Files:
src/bin/kill [netbsd-5]: kill.c
Log Message:
Pull up following revision(s) (requested by spz in ticket #1043):
bin/kill/kill.c: revision 1.26
Make sure that numerical signals and pids are in range for their types.
Fixes PR bin/42143
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.25.4.1 src/bin/kill/kill.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Manuel Bouyer <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/42143 CVS commit: [netbsd-4] src/bin/kill
Date: Sun, 18 Oct 2009 12:59:46 +0000
Module Name: src
Committed By: bouyer
Date: Sun Oct 18 12:59:46 UTC 2009
Modified Files:
src/bin/kill [netbsd-4]: kill.c
Log Message:
Pull up following revision(s) (requested by spz in ticket #1361):
bin/kill/kill.c: revision 1.26
Make sure that numerical signals and pids are in range for their types.
Fixes PR bin/42143
To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.24.4.1 src/bin/kill/kill.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: spz@NetBSD.org
State-Changed-When: Sun, 18 Oct 2009 15:26:11 +0000
State-Changed-Why:
pullups have been processed
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.