NetBSD Problem Report #55794
From jschauma@netmeister.org Sat Nov 7 16:04:19 2020
Return-Path: <jschauma@netmeister.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 485F11A9256
for <gnats-bugs@gnats.NetBSD.org>; Sat, 7 Nov 2020 16:04:19 +0000 (UTC)
Message-Id: <20201107160414.8A091859EA@panix.netmeister.org>
Date: Sat, 7 Nov 2020 11:04:14 -0500 (EST)
From: jschauma@netmeister.org
Reply-To: jschauma@netmeister.org
To: gnats-bugs@NetBSD.org
Subject: syslogd unchecked malloc(3)
X-Send-Pr-Version: 3.95
>Number: 55794
>Category: misc
>Synopsis: syslogd.c has an unchecked call to malloc(3)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: misc-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Nov 07 16:05:00 +0000 2020
>Last-Modified: Sat Nov 07 16:20:01 +0000 2020
>Originator: Jan Schaumann
>Release: NetBSD 9.0
>Organization:
>Environment:
System: NetBSD apue 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
usr.sbin/syslogd/syslogd.c contains an unchecked call to
malloc(3):
include_pid = malloc(MAX_PID_LEN+1);
snprintf(include_pid, MAX_PID_LEN+1, "%d", getpid());
>How-To-Repeat:
cd /usr/src
vi usr.sbin/syslogd/syslogd.c
>Fix:
--- syslogd.c 3 Feb 2019 03:19:31 -0000 1.131
+++ syslogd.c 7 Nov 2020 15:58:16 -0000
@@ -558,6 +558,13 @@
logerror("Failed to set uid to `%d'", uid);
die(0, 0, NULL);
}
+
+#define MAX_PID_LEN 5
+ include_pid = malloc(MAX_PID_LEN+1);
+ if (include_pid == NULL) {
+ logerror("Couldn't allocate include_pid");
+ die(0, 0, NULL);
+ }
/*
* We cannot detach from the terminal before we are sure we won't
* have a fatal error, because error message would not go to the
@@ -573,8 +580,6 @@
#endif /* __NetBSD_Version__ */
}
-#define MAX_PID_LEN 5
- include_pid = malloc(MAX_PID_LEN+1);
snprintf(include_pid, MAX_PID_LEN+1, "%d", getpid());
/*
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55794 CVS commit: src/usr.sbin/syslogd
Date: Sat, 7 Nov 2020 11:16:33 -0500
Module Name: src
Committed By: christos
Date: Sat Nov 7 16:16:33 UTC 2020
Modified Files:
src/usr.sbin/syslogd: syslogd.c
Log Message:
PR/55794: Jan Schaumann: Eliminate unchecked malloc
To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/usr.sbin/syslogd/syslogd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.