NetBSD Problem Report #926

From gnats  Wed Mar 29 13:22:39 1995
Received: from pain.lcs.mit.edu (pain.lcs.mit.edu [128.52.46.239]) by sun-lamp.cs.berkeley.edu (8.6.10/8.6.10) with ESMTP id NAA00306 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Wed, 29 Mar 1995 13:22:38 -0800
Message-Id: <9503292022.AA18394@leidecker.gsfc.nasa.gov>
Date: Wed, 29 Mar 95 15:22:20 -0500
From: Kenneth Stailey <kstailey@leidecker.gsfc.nasa.gov>
To: gnats-bugs@NetBSD.ORG
Subject: adventure tries to save while setuid games
X-Send-Pr-Version: 3.2

>Number:         926
>Category:       bin
>Synopsis:       adventure tries to save while setuid games
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 29 13:35:07 +0000 1995
>Closed-Date:    Tue May 21 10:43:21 +0000 1996
>Last-Modified:  Tue May 21 10:51:14 +0000 1996
>Originator:     Kenneth Stailey
>Release:        NetBSD 1.0A March 18th tarballs
>Organization:
self
>Environment:
System: NetBSD pluto 1.0A NetBSD 1.0A (PLUTO) #25: Tue Mar 28 13:17:39 EST 1995 ken@pluto:/usr/src/sys/arch/i386/compile/PLUTO i386


>Description:
	'adventure' is run via 'dm' which makes it setuid 'games'.
	Since it saves its state to let you resume later it must
	change back to the real uid to avoid letting you clobber
	any file that 'games' owns.
>How-To-Repeat:
	run adventure, use 'save' command
>Fix:

--- save.c.DIST	Wed Mar 29 15:03:59 1995
+++ save.c	Wed Mar 29 15:06:44 1995
@@ -123,18 +123,26 @@
 	char *s;
 	long sum;
 	int i;
+	int euid = -1;

 	crc_start();
 	for (p = save_array; p->address != NULL; p++)
 		sum = crc(p->address, p->width);
 	srandom((int) sum);

-	if ((out = fopen(outfile, "wb")) == NULL)
+	if (getuid() != geteuid()) { /* if running setuid */
+	  euid = geteuid();
+	  seteuid(getuid());	/* go back to being you */
+	}
+	if ((out = fopen(outfile, "w")) == NULL)
 	{
 	    fprintf(stderr,
 		"Hmm.  The name \"%s\" appears to be magically blocked.\n",
 		outfile);
 	    return 1;
+	}
+	if (euid != -1) {
+	  seteuid(euid);
 	}
 	fwrite(&sum, sizeof(sum), 1, out);      /* Here's the random() key */
 	for (p = save_array; p->address != NULL; p++)

--PAA04172.796508306/pluto.spacenet.com--


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: mrg 
State-Changed-When: Tue May 21 06:43:21 EDT 1996 
State-Changed-Why:  
adventure doens't required setuid-ness at all.  fixed by losing 
setuid-ness when we begin. 
>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.