NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/50454: fix wall(1) -g



>Number:         50454
>Category:       bin
>Synopsis:       fix wall(1) -g
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 21 03:55:00 +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++) {



Home | Main Index | Thread Index | Old Index