]> git.baikalelectronics.ru Git - kernel.git/commit
objtool: Fix truncated string warning
authorSergei Trofimovich <slyich@gmail.com>
Thu, 20 Jan 2022 23:37:48 +0000 (23:37 +0000)
committerJosh Poimboeuf <jpoimboe@redhat.com>
Mon, 24 Jan 2022 18:09:06 +0000 (10:09 -0800)
commita06f586f08fae0cfbe2fa386941a300dc35f310c
treee4bb841459d0e7c7e5ec434da03ee56d53dd379d
parent6e424e6bafec35e47db4b693fe41eff065b7dbf6
objtool: Fix truncated string warning

On GCC 12, the build fails due to a possible truncated string:

    check.c: In function 'validate_call':
    check.c:2865:58: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 9 [-Werror=format-truncation=]
     2865 |                 snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);
          |                                                          ^~

In theory it's a valid bug:

    static char pvname[16];
    int idx;
    ...
    idx = (rel->addend / sizeof(void *));
    snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);

There are only 7 chars for %d while it could take up to 9, so the
printed "pv_ops[%d]" string could get truncated.

In reality the bug should never happen, because pv_ops only has ~80
entries, so 7 chars for the integer is more than enough.  Still, it's
worth fixing.  Bump the buffer size by 2 bytes to silence the warning.

[ jpoimboe: changed size to 19; massaged changelog ]

Fixes: 5f2643e372a2 ("objtool: Support pv_opsindirect calls for noinstr")
Reported-by: Adam Borowski <kilobyte@angband.pl>
Reported-by: Martin Liška <mliska@suse.cz>
Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20220120233748.2062559-1-slyich@gmail.com
tools/objtool/check.c