[LU-9830] string truncation from snprintf in libcfs/util/parser.c::Parser_list_commands() Created: 04/Aug/17 Updated: 21/Jan/22 |
|
| Status: | Open |
| Project: | Lustre |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Oleg Drokin | Assignee: | WC Triage |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Severity: | 3 | ||||||||
| Rank (Obsolete): | 9223372036854775807 | ||||||||
| Description |
|
Modern gcc warns that: util/parser.c: In function Б─≤Parser_list_commandsБ─≥:
util/parser.c:575:25: error: Б─≤%2dБ─≥ directive output may be truncated writing between 2 and 10 bytes into a region of size 4 [-Werror=format-truncation=]
snprintf(fmt, 6, "%%-%2ds", char_max - len);
^~~
util/parser.c:575:21: note: directive argument in the range [1, 2147483647]
snprintf(fmt, 6, "%%-%2ds", char_max - len);
^~~~~~~~~
util/parser.c:575:4: note: Б─≤snprintfБ─≥ output between 6 and 14 bytes into a destination of size 6
snprintf(fmt, 6, "%%-%2ds", char_max - len);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[4]: *** [autoMakefile:669: libcfsutil_a-parser.o] Error 1
make[4]: Leaving directory '/home/green/smt/git/lustre-release/libcfs/libcfs'
there's some funky business going on with presumed column width so I guess we cannot just increase 6 to 14? |
| Comments |
| Comment by John Hammond [ 22/Aug/18 ] |
|
This does cause some commands names to be truncated in the output of lctl --list-commands: o:~# lctl --list-commands ... help lustre_build_versio exit quit ... changelog_register changelog_deregiste |
| Comment by Andreas Dilger [ 21/Jan/22 ] |
|
The compiler problems were fixed with patch https://review.whamcloud.com/35384 "LU-6142 util: Fix style issues for parser.c", but there are still a couple of commands truncated by one character - "changelog_deregister" and "lustre_build_version". The latter could likely be removed - it was superseded in v2_6_50_0-16-g593b6ab6d219 with "lctl get_param version" and "--version", but "changelog_deregister" can't. It would probably make sense to add a check to prevent new commands > 19 characters in length from being added. |