intel_reg: Fix truncate string in the snprintf
PATCH v3 1/1 intel_reg: Fix truncate string in the snprintf
From: Rodrigo Siqueira <[email protected]>
This patch fix the following GCC warning:
../tools/intel_reg.c: In function ‘dump_decode’:../tools/intel_reg.c:203:41: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
snprintf(decode, sizeof(decode), "\n%s", bin);
[..]../tools/intel_reg.c:200:40: warning: ‘%s’ directive output may be truncated writing up to 1023 bytes into a region of size 1022 [-Wformat-truncation=]
snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);
[..]
../tools/intel_reg.c:200:4: note: ‘snprintf’ output between 5 and 2051
bytes into a destination of size 1024
snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);[..]
The decode[] variable contains concatenated contents of bin[] and tmp[], both of which are allocated as 1024 bytes.
Allocating 1024 chars for bin[] seems like an overkill, since all it ever holds it the output of to_binary().
to_binary outputs fixed format:
--------------------------------------------------------------------
24 16 8 0
1 1 0 1 1 1 1 0 1 0 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1
--------------------------------------------------------------------
Which is 138 chars long (sans the new line).
We can limit the size of char bin[] to that number (-ish), and then slightly bump the size of decode[] to accommodate for combined sizes of tmp[] and bin[].
Changes since V1:
- Improve commit message
Changes since V2:
- updated commit message
- limit the amount of stack abuse
--- tools/intel_reg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/intel_reg.c +2 -2
@@ -180,9 +180,9 @@ static void to_binary(char *buf, size_t buflen, uint32_t val)static void dump_decode (struct config *config,struct reg *reg,uint32_t val) { -char decode[1024 ]; +char decode[1300 ];char tmp[1024 ]; -char bin[1024 ]; +char bin[200 ];if (config->binary)to_binary (bin,sizeof (bin), val);
Signature · 6 lines
2.17.1 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.BAT: success for intel_reg: Fix truncate string in the snprintf
== Series Details ==
== Series Details ==
Series: intel_reg: Fix truncate string in the snprintf
URL : https://patchwork.freedesktop.org/series/48751/
State : success
== Summary ==
= CI Bug Log - changes from CI_DRM_4706 -> IGTPW_1745 =
== Summary - WARNING ==
Minor unknown changes coming with IGTPW_1745 need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in IGTPW_1745, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://patchwork.freedesktop.org/api/1.0/series/48751/revisions/1/mbox/
== Possible new issues ==
Here are the unknown changes that may have been introduced in IGTPW_1745:
=== IGT changes ===
==== Possible regressions ====
{igt@pm_rpm@module-reload}:
fi-skl-6600u: PASS -> INCOMPLETE
==== Warnings ====
igt@drv_selftest@live_execlists:
fi-whl-u: SKIP -> PASS +1
{igt@kms_psr@primary_page_flip}:
fi-cnl-psr: DMESG-WARN -> DMESG-FAIL== Known issues ==
Here are the changes found in IGTPW_1745 that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@drv_selftest@live_guc:
fi-skl-guc: NOTRUN -> DMESG-WARN (fdo#107258, fdo#107175)
igt@kms_frontbuffer_tracking@basic:
{fi-byt-clapper}: PASS -> FAIL (fdo#103167)
==== Possible fixes ====
igt@drv_selftest@live_hangcheck:
fi-whl-u: DMESG-FAIL (fdo#106560) -> PASS
igt@gem_exec_suspend@basic-s3:
fi-blb-e6850: INCOMPLETE -> PASS
{igt@pm_rpm@module-reload}:
fi-cnl-psr: WARN (fdo#107602) -> PASS {name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#106560 https://bugs.freedesktop.org/show_bug.cgi?id=106560
fdo#107175 https://bugs.freedesktop.org/show_bug.cgi?id=107175
fdo#107258 https://bugs.freedesktop.org/show_bug.cgi?id=107258
fdo#107602 https://bugs.freedesktop.org/show_bug.cgi?id=107602
== Participating hosts (53 -> 48) ==
Additional (1): fi-skl-guc
Missing (6): fi-ilk-m540 fi-bxt-dsi fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600
== Build changes ==
* IGT: IGT_4609 -> IGTPW_1745
CI_DRM_4706: 6d5687919f3a3426243041b99111b576dd0576d0 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1745: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1745/
IGT_4609: 0bc9763af77bbb37f2ed65cc39c398e88db7d8e3 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1745/issues.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.IGT: success for intel_reg: Fix truncate string in the snprintf
In reply to Arkadiusz Hiler== Series Details ==
== Series Details ==
Series: intel_reg: Fix truncate string in the snprintf
URL : https://patchwork.freedesktop.org/series/48751/
State : success
== Summary ==
= CI Bug Log - changes from IGT_4609_full -> IGTPW_1745_full =
== Summary - WARNING ==
Minor unknown changes coming with IGTPW_1745_full need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in IGTPW_1745_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://patchwork.freedesktop.org/api/1.0/series/48751/revisions/1/mbox/
== Possible new issues ==
Here are the unknown changes that may have been introduced in IGTPW_1745_full:
=== IGT changes ===
==== Warnings ====
igt@perf_pmu@rc6:
shard-kbl: SKIP -> PASS== Known issues ==
Here are the changes found in IGTPW_1745_full that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@gem_exec_schedule@pi-ringfull-vebox:
shard-glk: NOTRUN -> FAIL (fdo#103158)
igt@gem_ppgtt@blt-vs-render-ctx0:
shard-kbl: PASS -> INCOMPLETE (fdo#106023, fdo#103665)
igt@gem_tiled_partial_pwrite_pread@writes:
shard-snb: PASS -> INCOMPLETE (fdo#105411)
igt@kms_plane@pixel-format-pipe-a-planes:
shard-snb: PASS -> FAIL (fdo#107161)
==== Possible fixes ====
igt@drv_selftest@live_hangcheck:
shard-kbl: DMESG-FAIL (fdo#106947, fdo#106560) -> PASS
igt@gem_ctx_isolation@bcs0-s3:
shard-kbl: INCOMPLETE (fdo#103665) -> PASS
igt@gem_exec_big:
shard-hsw: INCOMPLETE (fdo#103540) -> PASS
igt@kms_setmode@basic:
shard-apl: FAIL (fdo#99912) -> PASS fdo#103158 https://bugs.freedesktop.org/show_bug.cgi?id=103158
fdo#103540 https://bugs.freedesktop.org/show_bug.cgi?id=103540
fdo#103665 https://bugs.freedesktop.org/show_bug.cgi?id=103665
fdo#105411 https://bugs.freedesktop.org/show_bug.cgi?id=105411
fdo#106023 https://bugs.freedesktop.org/show_bug.cgi?id=106023
fdo#106560 https://bugs.freedesktop.org/show_bug.cgi?id=106560
fdo#106947 https://bugs.freedesktop.org/show_bug.cgi?id=106947
fdo#107161 https://bugs.freedesktop.org/show_bug.cgi?id=107161
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912
== Participating hosts (5 -> 5) ==
No changes in participating hosts
== Build changes ==
* IGT: IGT_4609 -> IGTPW_1745
* Linux: CI_DRM_4702 -> CI_DRM_4706
CI_DRM_4702: 0349bfb08204a6b44f16551c2be3b58563ff73d2 @ git://anongit.freedesktop.org/gfx-ci/linux
CI_DRM_4706: 6d5687919f3a3426243041b99111b576dd0576d0 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1745: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1745/
IGT_4609: 0bc9763af77bbb37f2ed65cc39c398e88db7d8e3 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1745/shards.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Hi,
First of all, thanks a lot for your feedback. I applied and tested the patch, and everything is fine. With this patch, IGT will be free of GCC warnings :)
Quoted 67 lines · Arkadiusz Hiler
From: Rodrigo Siqueira <[email protected]>
This patch fix the following GCC warning:
../tools/intel_reg.c: In function ‘dump_decode’:../tools/intel_reg.c:203:41: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
snprintf(decode, sizeof(decode), "\n%s", bin);
[..]../tools/intel_reg.c:200:40: warning: ‘%s’ directive output may be truncated writing up to 1023 bytes into a region of size 1022 [-Wformat-truncation=]snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin); [..] ../tools/intel_reg.c:200:4: note: ‘snprintf’ output between 5 and 2051 bytes into a destination of size 1024 snprintf(decode, sizeof(decode), " (%s)\n%s", tmp, bin);[..]
The decode[] variable contains concatenated contents of bin[] and tmp[], both of which are allocated as 1024 bytes.
Allocating 1024 chars for bin[] seems like an overkill, since all it ever holds it the output of
to_binary().
to_binaryoutputs fixed format:
--------------------------------------------------------------------
24 16 8 0
1 1 0 1 1 1 1 0 1 0 1 0 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1
--------------------------------------------------------------------
Which is 138 chars long (sans the new line).We can limit the size of char bin[] to that number (-ish), and then slightly bump the size of decode[] to accommodate for combined sizes of tmp[] and bin[].
Changes since V1:
- Improve commit message
Changes since V2:
- updated commit message
- limit the amount of stack abuseSigned-off-by Rodrigo Siqueira <[email protected]>Signed-off-by Arkadiusz Hiler <[email protected]>--- tools/intel_reg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/intel_reg.c +2
-2@@ -180,9 +180,9 @@ static void to_binary(char *buf, size_t buflen, uint32_t val)static void dump_decode (struct config *config,struct reg *reg,uint32_t val) { -char decode[1024 ]; +char decode[1300 ];char tmp[1024 ]; -char bin[1024 ]; +char bin[200 ];if (config->binary)to_binary (bin,sizeof (bin), val);Signature · 1 line
2.17.1
Signature · 9 lines
Rodrigo Siqueira http://siqueira.tech Graduate Student Department of Computer Science University of São Paulo _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev