Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Mar 2002 13:09:04 +0100
From:      Jens Schweikhardt <schweikh@schweikhardt.net>
To:        freebsd-audit@freebsd.org
Cc:        joerg@freebsd.org
Subject:   crontab changes for PR bin/22612; please comment
Message-ID:  <20020318130904.A3869@schweikhardt.net>

next in thread | raw e-mail | index | archive | help
hello, world\n

please comment on this patch (slightly different from the one in the PR
http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/22612)

Currently, checking for modification of the tmp file just looks at
the mtime and gives a false "no modification" if the edit took less
than 1 second. This is solved by simply comparing the whole struct stat.

Regards,

	Jens

Index: crontab.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/cron/crontab/crontab.c,v
retrieving revision 1.18
diff -u -r1.18 crontab.c
--- crontab.c	9 Jul 2001 09:23:57 -0000	1.18
+++ crontab.c	18 Mar 2002 11:51:13 -0000
@@ -44,6 +44,7 @@
 # include <locale.h>
 #endif
 
+#include <string.h>
 
 #define NHEADER_LINES 3
 
@@ -304,8 +305,7 @@
 	char		n[MAX_FNAME], q[MAX_TEMPSTR], *editor;
 	FILE		*f;
 	int		ch, t, x;
-	struct stat	statbuf, fsbuf;
-	time_t		mtime;
+	struct stat	fsbuf, statbuf;
 	WAIT_T		waiter;
 	PID_T		pid, xpid;
 	mode_t		um;
@@ -380,7 +380,6 @@
 	}
 	if (statbuf.st_dev != fsbuf.st_dev || statbuf.st_ino != fsbuf.st_ino)
 		errx(ERROR_EXIT, "temp file must be edited in place");
-	mtime = statbuf.st_mtime;
 
 	if ((!(editor = getenv("VISUAL")))
 	 && (!(editor = getenv("EDITOR")))
@@ -446,7 +445,11 @@
 	}
 	if (statbuf.st_dev != fsbuf.st_dev || statbuf.st_ino != fsbuf.st_ino)
 		errx(ERROR_EXIT, "temp file must be edited in place");
-	if (mtime == statbuf.st_mtime) {
+	/*
+	 * Compare the whole struct stat instead of just the mtime;  this
+	 * avoids ugly #ifdefs because struct stat changes with _POSIX_SOURCE.
+	 */
+	if (memcmp(&fsbuf, &statbuf, sizeof(fsbuf)) == 0) {
 		warnx("no changes made to crontab");
 		goto remove;
 	}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020318130904.A3869>