Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Apr 1997 22:28:19 +0200 (CEST)
From:      Philippe Charnier <charnier@xp11.frmug.org>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/3258: hardcoded and old value of LOGNAMESIZE in atrun
Message-ID:  <199704112028.WAA17657@xp11.frmug.org>
Resent-Message-ID: <199704112240.PAA26538@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         3258
>Category:       bin
>Synopsis:       atrun still use old LOGNAMESIZE value
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 11 15:40:01 PDT 1997
>Last-Modified:
>Originator:     Philippe Charnier
>Organization:
>Release:        FreeBSD 3.0-CURRENT i386
>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] == '-') {
>Audit-Trail:
>Unformatted:



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