On Mon, May 13, 2002 at 11:57:49AM +0800, Fabrice MARIE wrote:
>
> Hello,
>
> stat-3.3-3mdk is printing garbage after the access permissions :
>
> # stat /etc/rc.d/rc.sysinit
> File: "/etc/rc.d/rc.sysinit"
> Size: 33837 Blocks: 72 IO Block: 4096 Regular File
> Device: 302h/770d Inode: 3401 Links: 1
> Access: (0755/-rwxr-xr-x??p?) Uid: ( 0/ root) Gid: ( 0/ root)
> Access: Fri Mar 15 23:46:43 2002
> Modify: Fri Mar 15 23:46:43 2002
> Change: Mon Apr 1 00:37:19 2002
>
> note the garbage : ??p? after the correct -rwxr-xr-x.
>
Yikes. You're right.
Thanks for the patch! :-)
For printf() it should not require the %s since we should be pretty sure
that the access permissions -rwxrwxrwx should not contain any format string
characters. But it should be safe to have %s anyway.
> Here's the obvious fix.
>
> --- stat.old 2002-05-13 11:51:33.000000000 +0800
> +++ stat.c 2002-05-13 11:51:56.000000000 +0800
> @@ -247,8 +247,9 @@
>
> void print_human_access(struct stat *statbuf)
> {
> - char access[10];
> + char access[11];
>
> + access[10] = '\0';
> access[9] = (statbuf->st_mode & S_IXOTH) ?
> ((statbuf->st_mode & S_ISVTX) ? 't' : 'x') :
> ((statbuf->st_mode & S_ISVTX) ? 'T' : '-');
> @@ -291,7 +292,7 @@
> default:
> access[0] = '?';
> }
> - printf (access);
> + printf ("%s", access);
> }
>
> I didn't check the rest of the printf to see
> if they were missing their format string though..
>
> Have a nice day,
>
> Fabrice.
> --
> Fabrice MARIE
> Senior R&D Engineer
> Celestix Networks
> http://www.celestix.com/
>
> "Silly hacker, root is for administrators"
> -Unknown