From 2f593094f0c4f828fd81a3b052ee426135135694 Mon Sep 17 00:00:00 2001 From: jsm Date: Sun, 12 Sep 1999 09:02:20 +0000 Subject: Security improvements for games (largely from or inspired by OpenBSD). Games which run setgid from dm, but don't need to, should drop their privileges at startup. Games which have a scorefile should open it at startup, then drop all privileges leaving just the open writable file descriptor. If the game can invoke subprocesses, this should be made close-on-exec. Games with scorefiles should make sure they do not get a file descriptor < 3. (Otherwise, they could get confused and corrupt the scorefile when using stdin, stdout or stderr.) Some old setuid revokes from the days of setuid games change into gid revokes. --- robots/score.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'robots/score.c') diff --git a/robots/score.c b/robots/score.c index ddc8ce56..ee0b5b18 100644 --- a/robots/score.c +++ b/robots/score.c @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.9 1999/09/08 21:57:20 jsm Exp $ */ +/* $NetBSD: score.c,v 1.10 1999/09/12 09:02:22 jsm Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: score.c,v 1.9 1999/09/08 21:57:20 jsm Exp $"); +__RCSID("$NetBSD: score.c,v 1.10 1999/09/12 09:02:22 jsm Exp $"); #endif #endif /* not lint */ @@ -116,18 +116,17 @@ write_score(inf) * top list. */ void -score() +score(score_wfd) + int score_wfd; { - int inf; + int inf = score_wfd; SCORE *scp; int uid; bool done_show = FALSE; Newscore = FALSE; - if ((inf = open(Scorefile, O_RDWR)) < 0) { - warn("opening `%s'", Scorefile); + if (inf < 0) return; - } read_score(inf); @@ -161,7 +160,7 @@ score() if (!Newscore) { Full_clear = FALSE; - close(inf); + lseek(inf, 0, SEEK_SET); return; } else @@ -191,7 +190,7 @@ score() if (Newscore) { write_score(inf); } - close(inf); + lseek(inf, 0, SEEK_SET); } void -- cgit v1.2.3