NetBSD Problem Report #50454

From www@NetBSD.org  Sat Nov 21 03:52:42 2015
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 6555AA65E7
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 21 Nov 2015 03:52:42 +0000 (UTC)
Message-Id: <20151121035240.BE424A66E4@mollari.NetBSD.org>
Date: Sat, 21 Nov 2015 03:52:40 +0000 (UTC)
From: fstd.lkml@gmail.com
Reply-To: fstd.lkml@gmail.com
To: gnats-bugs@NetBSD.org
Subject: fix wall(1) -g 
X-Send-Pr-Version: www-1.0

>Number:         50454
>Category:       bin
>Synopsis:       fix wall(1) -g
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 21 03:55:00 +0000 2015
>Closed-Date:    Thu Nov 26 20:28:47 +0000 2015
>Last-Modified:  Thu Nov 26 20:28:47 +0000 2015
>Originator:     Timo Buhrmester
>Release:        7.0
>Organization:
>Environment:
NetBSD dedi 7.0_STABLE NetBSD 7.0_STABLE (DEDIKERN) #0: Wed Nov 18 03:23:46 CET 2015  build@dedi:/stor/netbsd/obj/sys/arch/amd64/compile/DEDIKERN amd64

>Description:
Due to a missing sizeof, wall(1) allocates too little memory to hold the group member list which leads to undefined behavior when attempting to send messages to all users in a group using wall -g.
Below is a patch to correct this.
While there, remove two unnecessary typecasts.
>How-To-Repeat:
echo foo | wall -g nonempty_group
>Fix:
--- usr.bin/wall/wall.c.orig	2015-11-21 04:44:01.000000000 +0100
+++ usr.bin/wall/wall.c	2015-11-21 04:44:04.000000000 +0100
@@ -169,12 +169,12 @@
 	for (i = 0; grp->gr_mem[i]; i++)
 		continue;

-	g = (struct wallgroup *)malloc(sizeof *g);
+	g = malloc(sizeof *g);
 	if (g == NULL)
 		err(1, "malloc");
 	g->gid = grp->gr_gid;
 	g->name = name;
-	g->mem = (char **)malloc(i + 1);
+	g->mem = malloc((i + 1) * sizeof *g->mem);
 	if (g->mem == NULL)
 		err(1, "malloc");
 	for (i = 0; grp->gr_mem[i] != NULL; i++) {

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50454 CVS commit: src/usr.bin/wall
Date: Sat, 21 Nov 2015 09:59:51 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sat Nov 21 14:59:51 UTC 2015

 Modified Files:
 	src/usr.bin/wall: Makefile wall.c

 Log Message:
 PR/50454: Timo Buhrmester: Fix wrong allocation for wall(1) -g
 Modernize.


 To generate a diff of this commit:
 cvs rdiff -u -r1.10 -r1.11 src/usr.bin/wall/Makefile
 cvs rdiff -u -r1.29 -r1.30 src/usr.bin/wall/wall.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: mrg@NetBSD.org
State-Changed-When: Thu, 26 Nov 2015 20:28:47 +0000
State-Changed-Why:
christos fixed it.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(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-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.