From d80101c91c47da48b2813a2824b5e3d0446c3e90 Mon Sep 17 00:00:00 2001 From: itojun Date: Wed, 25 Sep 2002 04:57:59 +0000 Subject: [PATCH] Allocate vis_user on the stack instead of using malloc(). This way we don't have to worry about malloc() failure. Also closes a memory leak since vis_user was never free()d. Lack of malloc() checking pointed out by Peter Werner. from openbsd --- libexec/talkd/announce.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libexec/talkd/announce.c b/libexec/talkd/announce.c index f235314c42d3..905282da0487 100644 --- a/libexec/talkd/announce.c +++ b/libexec/talkd/announce.c @@ -1,4 +1,4 @@ -/* $NetBSD: announce.c,v 1.15 2002/03/04 01:40:56 enami Exp $ */ +/* $NetBSD: announce.c,v 1.16 2002/09/25 04:57:59 itojun Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)announce.c 8.3 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: announce.c,v 1.15 2002/03/04 01:40:56 enami Exp $"); +__RCSID("$NetBSD: announce.c,v 1.16 2002/09/25 04:57:59 itojun Exp $"); #endif #endif /* not lint */ @@ -110,7 +110,7 @@ print_mesg(tty, request, remote_machine) char line_buf[N_LINES][N_CHARS]; int sizes[N_LINES]; char big_buf[(N_LINES + 1) * N_CHARS]; - char *bptr, *lptr, *vis_user; + char *bptr, *lptr, vis_user[sizeof(request->l_name) * 4]; int i, j, max_size; i = 0; @@ -129,7 +129,6 @@ print_mesg(tty, request, remote_machine) sizes[i] = strlen(line_buf[i]); max_size = max(max_size, sizes[i]); i++; - vis_user = (char *)malloc(strlen(request->l_name) * 4 + 1); strvis(vis_user, request->l_name, VIS_CSTYLE); (void)snprintf(line_buf[i], N_CHARS, "talk: connection requested by %s@%s.", vis_user, remote_machine);