NetBSD Problem Report #52923

From www@NetBSD.org  Sat Jan 13 12:56:00 2018
Return-Path: <www@NetBSD.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 435EB7A1B2
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 13 Jan 2018 12:56:00 +0000 (UTC)
Message-Id: <20180113125559.3E1467A21A@mollari.NetBSD.org>
Date: Sat, 13 Jan 2018 12:55:59 +0000 (UTC)
From: andrew.hall649@gmail.com
Reply-To: andrew.hall649@gmail.com
To: gnats-bugs@NetBSD.org
Subject: sudo segfaults when the system hostname is not set
X-Send-Pr-Version: www-1.0

>Number:         52923
>Category:       pkg
>Synopsis:       sudo segfaults when the system hostname is not set
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 13 13:00:00 +0000 2018
>Closed-Date:    Sun Jan 14 15:30:29 +0000 2018
>Last-Modified:  Fri Jan 19 20:25:01 +0000 2018
>Originator:     Andrew Hall
>Release:        NetBSD 7.1.1 (pkgsrc 2017Q3)
>Organization:
>Environment:
NetBSD  7.1.1 NetBSD 7.1.1 (GENERIC.201712222334Z) amd64
>Description:
If the system hostname is not set sudo will pass a blank string containing a null terminator instead of NULL to strdup() causing the program to segfault. It is possible however to use the "-h" switch to manually set the hostname. A fix has been produced upstream to correct this issue.

The version the bug was encountered in was sudo-1.8.21p2 however it may be present in earlier versions.
>How-To-Repeat:
Once sudo-1.8.21p2 has been installed, unset the system hostname and run sudo. The program will then segfault.
>Fix:
A fix has been applied to sudo's HEAD and can be found at https://bugzilla.sudo.ws/show_bug.cgi?id=807). In the meanwhile following FreeBSD (https://svnweb.freebsd.org/ports/head/security/sudo/files/patch-bug222510?view=log) the following patch should be applied (SHA1 checksum: 2fa0e9f0af3c74c0ac248d775dff920ddc07b627):

diff -r 926deea0d506 -r fafb3a3083cb lib/util/gethostname.c
--- lib/util/gethostname.c	Tue Oct 17 14:28:38 2017 -0600
+++ lib/util/gethostname.c	Fri Oct 20 07:37:40 2017 -0600
@@ -42,7 +42,7 @@

     hname = malloc(host_name_max + 1);
     if (hname != NULL) {
-	if (gethostname(hname, host_name_max + 1) == 0) {
+	if (gethostname(hname, host_name_max + 1) == 0 && *hname != '\0') {
 	    /* Old gethostname() may not NUL-terminate if there is no room. */
 	    hname[host_name_max] = '\0';
 	} else {

>Release-Note:

>Audit-Trail:
From: "Maya Rashish" <maya@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52923 CVS commit: pkgsrc/security/sudo
Date: Sun, 14 Jan 2018 15:29:38 +0000

 Module Name:	pkgsrc
 Committed By:	maya
 Date:		Sun Jan 14 15:29:38 UTC 2018

 Modified Files:
 	pkgsrc/security/sudo: Makefile distinfo
 Added Files:
 	pkgsrc/security/sudo/patches: patch-lib_util_gethostname.c

 Log Message:
 sudo: avoid segfault if hostname is empty

 from andrew hall in pr pkg/52923
 PKGREVISION++


 To generate a diff of this commit:
 cvs rdiff -u -r1.157 -r1.158 pkgsrc/security/sudo/Makefile
 cvs rdiff -u -r1.93 -r1.94 pkgsrc/security/sudo/distinfo
 cvs rdiff -u -r0 -r1.1 \
     pkgsrc/security/sudo/patches/patch-lib_util_gethostname.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->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sun, 14 Jan 2018 15:30:29 +0000
State-Changed-Why:
applied, thanks for the patch.


From: "S.P.Zeidler" <spz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52923 CVS commit: [pkgsrc-2017Q4] pkgsrc/security/sudo
Date: Fri, 19 Jan 2018 20:22:41 +0000

 Module Name:	pkgsrc
 Committed By:	spz
 Date:		Fri Jan 19 20:22:41 UTC 2018

 Modified Files:
 	pkgsrc/security/sudo [pkgsrc-2017Q4]: Makefile distinfo
 Added Files:
 	pkgsrc/security/sudo/patches [pkgsrc-2017Q4]:
 	    patch-lib_util_gethostname.c

 Log Message:
 Pullup ticket #5680 - requested by maya
 security/sudo: function fix

 Revisions pulled up:
 - security/sudo/Makefile                                        1.158
 - security/sudo/distinfo                                        1.94
 - security/sudo/patches/patch-lib_util_gethostname.c            1.1

 -------------------------------------------------------------------
    Module Name:	pkgsrc
    Committed By:	maya
    Date:		Sun Jan 14 15:29:38 UTC 2018

    Modified Files:
    	pkgsrc/security/sudo: Makefile distinfo
    Added Files:
    	pkgsrc/security/sudo/patches: patch-lib_util_gethostname.c

    Log Message:
    sudo: avoid segfault if hostname is empty

    from andrew hall in pr pkg/52923
    PKGREVISION++

    To generate a diff of this commit:
    cvs rdiff -u -r1.157 -r1.158 pkgsrc/security/sudo/Makefile
    cvs rdiff -u -r1.93 -r1.94 pkgsrc/security/sudo/distinfo
    cvs rdiff -u -r0 -r1.1 \
        pkgsrc/security/sudo/patches/patch-lib_util_gethostname.c


 To generate a diff of this commit:
 cvs rdiff -u -r1.157 -r1.157.6.1 pkgsrc/security/sudo/Makefile
 cvs rdiff -u -r1.93 -r1.93.6.1 pkgsrc/security/sudo/distinfo
 cvs rdiff -u -r0 -r1.1.2.2 \
     pkgsrc/security/sudo/patches/patch-lib_util_gethostname.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.