]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit
xfs_repair: detect null buf passed to duration
authorDarrick J. Wong <djwong@kernel.org>
Sat, 1 Jun 2024 17:58:53 +0000 (10:58 -0700)
committerCarlos Maiolino <cem@kernel.org>
Mon, 17 Jun 2024 11:46:13 +0000 (13:46 +0200)
commit7ccc7965ed53e82fb92d235ccf5e79bf6fa04009
tree68d1a3c3879dd830bd8f173e64b2f22fd9141185
parent256c693121f6f005e419272782d4b1868607cdc8
xfs_repair: detect null buf passed to duration

gcc 12.2 with ubsan and fortify turned on complains about this:

In file included from /usr/include/stdio.h:906,
                 from ../include/platform_defs.h:9,
                 from ../include/libxfs.h:16,
                 from progress.c:3:
In function ‘sprintf’,
    inlined from ‘duration’ at progress.c:443:4:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:30:10: error: null destination pointer [-Werror=format-overflow=]
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~

I think this is a false negative since all callers are careful not to
pass in a null pointer.  Unfortunately the compiler cannot detect that
since this isn't a static function and complains.  Fix this by adding an
explicit declaration that buf isn't null.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
repair/progress.h