From charnier@xp11.frmug.org  Fri Apr 11 15:34:08 1997
Received: from frmug.org (frmug-gw.frmug.org [193.56.58.252])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id PAA26154
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Apr 1997 15:32:59 -0700 (PDT)
Received: (from uucp@localhost)
	by frmug.org (8.8.5/8.8.5/frmug-2.0) with UUCP id AAA23481
	for FreeBSD-gnats-submit@freebsd.org; Sat, 12 Apr 1997 00:31:35 +0200 (MET DST)
Received: (from charnier@localhost)
	by xp11.frmug.org (8.8.5/8.8.5/xp11-uucp-1.1) id WAA17657;
	Fri, 11 Apr 1997 22:28:19 +0200 (CEST)
Message-Id: <199704112028.WAA17657@xp11.frmug.org>
Date: Fri, 11 Apr 1997 22:28:19 +0200 (CEST)
From: Philippe Charnier <charnier@xp11.frmug.org>
Reply-To: charnier@xp11.frmug.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: hardcoded and old value of LOGNAMESIZE in atrun
X-Send-Pr-Version: 3.2

>Number:         3258
>Category:       bin
>Synopsis:       atrun still use old LOGNAMESIZE value
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 11 15:40:01 PDT 1997
>Closed-Date:    Sat Apr 12 11:05:13 EST 1997
>Last-Modified:  Sat Apr 12 10:50:01 PDT 1997
>Originator:     Philippe Charnier
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:

	

>Description:

	atrun still think that LOGNAMESIZE is 8. With printf, the %*s format
can be used to supply a field width. It is not possible to do the same using
fscanf. This is why the enclosed patch create the format before calling
fscanf. The value of 49 assumes that LOGNAMESIZE will not become more than 99.
	#!/bin/sh        will use  9 char.
	\n                         1
	# atrun uid=              12
	%%ld                       3 will become '%ld'
	 gid=                      5
	%%ld                       3
	\n                         1
	# mail %%                  8 will become '# mail %'
	%d                         2 will become less than 99
	s %%d                      4
	\0                         1
                                 -----
                                  49

>How-To-Repeat:

>Fix:
	
Index: atrun.c
===================================================================
RCS file: /home2h/FreeBSD.cvsroot/src/libexec/atrun/atrun.c,v
retrieving revision 1.9
diff -u -r1.9 atrun.c
--- atrun.c	1997/03/28 15:48:03	1.9
+++ atrun.c	1997/04/07 19:30:02
@@ -29,6 +29,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <sys/param.h>
 #include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
@@ -42,12 +43,19 @@
 #include <time.h>
 #include <unistd.h>
 #include <syslog.h>
+#include <utmp.h>
 #ifdef __FreeBSD__
 #include <paths.h>
 #else
 #include <getopt.h>
 #endif
 
+#if (MAXLOGNAME-1) > UT_NAMESIZE
+#define LOGNAMESIZE UT_NAMESIZE
+#else
+#define LOGNAMESIZE (MAXLOGNAME-1)
+#endif
+
 /* Local headers */
 
 #include "gloadavg.h"
@@ -108,7 +116,7 @@
     pid_t pid;
     int fd_out, fd_in;
     int queue;
-    char mailbuf[9];
+    char mailbuf[LOGNAMESIZE + 1], fmt[49];
     char *mailname = NULL;
     FILE *stream;
     int send_mail = 0;
@@ -197,11 +205,10 @@
 
     fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC);
 
-    if (fscanf(stream, "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %8s %d",
-         &nuid, &ngid, mailbuf, &send_mail) != 4)
-    {
-	syslog(LOG_ERR,"File %s is in wrong format - aborting",
-		filename);
+    snprintf(fmt, 49, "#!/bin/sh\n# atrun uid=%%ld gid=%%ld\n# mail %%%ds %%d",
+                          LOGNAMESIZE);
+    if (fscanf(stream, fmt, &nuid, &ngid, mailbuf, &send_mail) != 4) {
+	syslog(LOG_ERR,"File %s is in wrong format - aborting", filename);
 	exit(EXIT_FAILURE);
     }
     if (mailbuf[0] == '-') {
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: davidn 
State-Changed-When: Sat Apr 12 11:05:13 EST 1997 
State-Changed-Why:  

Patch applied, thanks! 

Checking in atrun.c; 
/home/ncvs/src/libexec/atrun/atrun.c,v  <--  atrun.c 
new revision: 1.10; previous revision: 1.9 
done 

From: Bill Fenner <fenner@parc.xerox.com>
To: charnier@xp11.frmug.org
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/3258: hardcoded and old value of LOGNAMESIZE in atrun 
Date: Sat, 12 Apr 1997 10:45:43 PDT

 Couldn't this just be something like
 
 "#!/bin/sh\n# atrun uid=%ld gid=%ld\n# mail %[^ ]%*[ ]%d"
 
 and eliminate the dependency on the definition completely?  Might even
 be backwards compatible with files created by an old "at" command...
 
   Bill
>Unformatted:
