From owner-freebsd-bugs Fri Apr 11 15:40:05 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id PAA26550 for bugs-outgoing; Fri, 11 Apr 1997 15:40:05 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id PAA26538; Fri, 11 Apr 1997 15:40:02 -0700 (PDT) Resent-Date: Fri, 11 Apr 1997 15:40:02 -0700 (PDT) Resent-Message-Id: <199704112240.PAA26538@freefall.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, charnier@xp11.frmug.org 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 ; 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 Reply-To: charnier@xp11.frmug.org To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/3258: hardcoded and old value of LOGNAMESIZE in atrun Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >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 #include #include +#include #include #include #include @@ -42,12 +43,19 @@ #include #include #include +#include #ifdef __FreeBSD__ #include #else #include #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: