NULL pointer passed to printf() in sbin/mount/mount.c

From: Giorgos Keramidas <keramida_at_ceid.upatras.gr>
Date: Fri, 3 Mar 2006 03:36:26 +0200
Hi Craig & -current,

After a recent update to HEAD, I noticed that ``mount -p'' no longer
prints the flags of the mounted filesystems correctly:

    keramida_at_flame:/home/keramida$ mount -p
    /dev/ad0s2a     /       ufs (null)      1 1
    devfs   /dev    devfs (null)    0 0
    /dev/ad0s2d     /var    ufs (null)      2 2
    /dev/ad0s2e     /usr    ufs (null)      2 2
    /dev/ad0s2f     /home   ufs (null)      2 2
    /dev/md0        /tmp    ufs (null)      2 2
    devfs   /var/named/dev  devfs (null)    0 0
    keramida_at_flame:/home/keramida$

Here ``(null)'' seems to be the output of a printf %s format which got a
NULL pointer.  The following patch for src/sbin/mount/mount.c triggers
an assertion quite reproducibly:

% build_at_flame:/home/build/src/sbin/mount$ svn di
% Index: mount.c
% ===================================================================
% --- mount.c     (revision 23)
% +++ mount.c     (working copy)
% _at__at_ -46,6 +46,7 _at__at_
%  #include <sys/stat.h>
%  #include <sys/wait.h>
%
% +#include <assert.h>
%  #include <ctype.h>
%  #include <err.h>
%  #include <errno.h>
% _at__at_ -754,6 +755,7 _at__at_
%         char *opts;
%
%         opts = flags2opts(ent->f_flags);
% +       assert(opts != NULL);
%         printf("%s\t%s\t%s %s", ent->f_mntfromname, ent->f_mntonname,
%             ent->f_fstypename, opts);
%         free(opts);
% build_at_flame:/home/build/src/sbin/mount$

Any idea how the following core dump can be fixed for HEAD?

% build_at_flame:/home/build/src/sbin/mount$ export MAKEOBJDIRPREFIX=/home/build/obj
% build_at_flame:/home/build/src/sbin/mount$ export DEBUG_FLAGS='-g'
% build_at_flame:/home/build/src/sbin/mount$ make cleandir
% rm -f mount mount.o mount_fs.o getmntopts.o vfslist.o mount.8.gz mount.8.cat.gz
% rm -f .depend GPATH GRTAGS GSYMS GTAGS
% build_at_flame:/home/build/src/sbin/mount$ make cleandir
% rm -f mount mount.o mount_fs.o getmntopts.o vfslist.o mount.8.gz mount.8.cat.gz
% rm -f .depend GPATH GRTAGS GSYMS GTAGS
% build_at_flame:/home/build/src/sbin/mount$ make obj
% /home/build/obj/home/build/src/sbin/mount created for /home/build/src/sbin/mount
% build_at_flame:/home/build/src/sbin/mount$ make
% cc -O2 -fno-strict-aliasing -pipe  -g -Wsystem-headers -Werror -Wall \
%   -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes \
%   -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual \
%   -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter \
%   -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls \
%   -c /home/build/src/sbin/mount/mount.c
% cc -O2 -fno-strict-aliasing -pipe  -g -Wsystem-headers -Werror -Wall \
%   -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes \
%   -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual \
%   -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter \
%   -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls \
%   -c /home/build/src/sbin/mount/mount_fs.c
% cc -O2 -fno-strict-aliasing -pipe  -g -Wsystem-headers -Werror -Wall \
%   -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes \
%   -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual \
%   -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter \
%   -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls \
%   -c /home/build/src/sbin/mount/getmntopts.c
% cc -O2 -fno-strict-aliasing -pipe  -g -Wsystem-headers -Werror -Wall \
%   -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes \
%   -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual \
%   -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter \
%   -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls \
%   -c /home/build/src/sbin/mount/vfslist.c
% cc -O2 -fno-strict-aliasing -pipe  -g -Wsystem-headers -Werror -Wall \
%   -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes \
%   -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual \
%   -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter \
%   -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls  \
%   -o mount mount.o mount_fs.o getmntopts.o vfslist.o
% gzip -cn /home/build/src/sbin/mount/mount.8 > mount.8.gz
% build_at_flame:/home/build/src/sbin/mount$ /home/build/obj/home/build/src/sbin/mount/mount -p
% Assertion failed: (opts != NULL), function putfsent, file /home/build/src/sbin/mount/mount.c, line 758.
% Abort trap: 6 (core dumped)
% build_at_flame:/home/build/src/sbin/mount$
Received on Fri Mar 03 2006 - 00:37:24 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:53 UTC