Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsafe use of strncpy in OpenThread dns-sd code. #13392

Conversation

bzbarsky-apple
Copy link
Contributor

@bzbarsky-apple bzbarsky-apple commented Jan 8, 2022

For the three uses where we are copying data of some computed size
into a buffer, add checks that the size is not too big for the buffer
(and in particular that we will be able to null-terminate after
copying).

For the one use where we are copying the entire buffer between two
identical-sized buffers:

  1. Assert that the target buffer us not smaller than the source buffer.

  2. Use CopyString to ensure null-termination even if the source is not
    null-terminated.

Problem

Looks to me like this code can end up with buffer overruns.

Change overview

Avoid those buffer overruns.

Testing

I have no idea how to test this code with data that would in fact trigger the buffer overruns without this PR, but it would be a really good idea to do that... Ideas on how to do it are very welcome.

@github-actions
Copy link

github-actions bot commented Jan 8, 2022

PR #13392: Size comparison from 5d0c314 to 8f3bfa2

Increases (14 builds for efr32, k32w, nrfconnect)
platform target config section 5d0c314 8f3bfa2 change % change
efr32 lighting-app BRD4161A (read only) 829244 829260 16 0.0
.text 829236 829252 16 0.0
BRD4161A+rpc (read only) 816888 816904 16 0.0
.text 816880 816896 16 0.0
window-app BRD4161A (read only) 802692 802724 32 0.0
.text 802684 802716 32 0.0
k32w light k32w061+release (read/write) 655324 655356 32 0.0
.text 570900 570932 32 0.0
lock k32w061+release (read/write) 659616 659632 16 0.0
.text 574876 574892 16 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 937115 937131 16 0.0
text 633324 633348 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 923511 923543 32 0.0
text 628636 628660 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 848094 848110 16 0.0
text 550256 550280 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 909259 909275 16 0.0
text 611188 611212 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 820418 820450 32 0.0
text 528164 528188 24 0.0
pump-app nrf52840dk_nrf52840 (read/write) 910523 910555 32 0.0
text 612404 612428 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 907339 907355 16 0.0
text 609936 609960 24 0.0
shell nrf52840dk_nrf52840 (read/write) 797935 797951 16 0.0
text 533508 533532 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 710750 710766 16 0.0
text 451188 451212 24 0.0
Full report (31 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
platform target config section 5d0c314 8f3bfa2 change % change
efr32 lighting-app BRD4161A (read only) 829244 829260 16 0.0
(read/write) 126996 126996 0 0.0
.bss 125120 125120 0 0.0
.data 1876 1876 0 0.0
.text 829236 829252 16 0.0
BRD4161A+rpc (read only) 816888 816904 16 0.0
(read/write) 143656 143656 0 0.0
.bss 141680 141680 0 0.0
.data 1976 1976 0 0.0
.text 816880 816896 16 0.0
window-app BRD4161A (read only) 802692 802724 32 0.0
(read/write) 125936 125936 0 0.0
.bss 124104 124104 0 0.0
.data 1832 1832 0 0.0
.text 802684 802716 32 0.0
esp32 all-clusters-app c3devkit (read only) 891904 891904 0 0.0
(read/write) 1314010 1314010 0 0.0
.dram0.bss 69464 69464 0 0.0
.dram0.data 14236 14236 0 0.0
.flash.rodata 177248 177248 0 0.0
.flash.text 891904 891904 0 0.0
.iram0.text 62254 62254 0 0.0
m5stack (read only) 951843 951843 0 0.0
(read/write) 445592 445592 0 0.0
.dram0.bss 73960 73960 0 0.0
.dram0.data 34064 34064 0 0.0
.flash.rodata 206560 206560 0 0.0
.flash.text 946459 946459 0 0.0
.iram0.text 122671 122671 0 0.0
k32w light k32w061+release (read/write) 655324 655356 32 0.0
.bss 76776 76776 0 0.0
.data 1848 1848 0 0.0
.text 570900 570932 32 0.0
lock k32w061+release (read/write) 659616 659632 16 0.0
.bss 77072 77072 0 0.0
.data 1868 1868 0 0.0
.text 574876 574892 16 0.0
linux chip-tool-ipv6only arm64 (read only) 7056652 7056652 0 0.0
(read/write) 326113 326113 0 0.0
.bss 54865 54865 0 0.0
.data 1096 1096 0 0.0
.data.rel.ro 209392 209392 0 0.0
.dynamic 560 560 0 0.0
.got 57072 57072 0 0.0
.init 24 24 0 0.0
.init_array 168 168 0 0.0
.rodata 384564 384564 0 0.0
.text 5978228 5978228 0 0.0
thermostat-no-ble arm64 (read only) 2033804 2033804 0 0.0
(read/write) 145089 145089 0 0.0
.bss 64657 64657 0 0.0
.data 880 880 0 0.0
.data.rel.ro 72624 72624 0 0.0
.dynamic 560 560 0 0.0
.got 4000 4000 0 0.0
.init 24 24 0 0.0
.init_array 296 296 0 0.0
.rodata 128988 128988 0 0.0
.text 1691168 1691168 0 0.0
mbed all-clusters-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2348560 2348560 0 0.0
.bss 188724 188724 0 0.0
.data 5312 5312 0 0.0
.text 1311136 1311136 0 0.0
lighting-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2330752 2330752 0 0.0
.bss 180544 180544 0 0.0
.data 5552 5552 0 0.0
.text 1293352 1293352 0 0.0
lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2303904 2303904 0 0.0
.bss 179592 179592 0 0.0
.data 5544 5544 0 0.0
.text 1266504 1266504 0 0.0
pigweed-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 1140008 1140008 0 0.0
.bss 11756 11756 0 0.0
.data 4368 4368 0 0.0
.text 103392 103392 0 0.0
shell CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2054256 2054256 0 0.0
.bss 157060 157060 0 0.0
.data 4864 4864 0 0.0
.text 1016856 1016856 0 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 937115 937131 16 0.0
bss 118112 118112 0 0.0
rodata 108120 108120 0 0.0
text 633324 633348 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 923511 923543 32 0.0
bss 115156 115156 0 0.0
rodata 101548 101548 0 0.0
text 628636 628660 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 848094 848110 16 0.0
bss 116004 116004 0 0.0
rodata 101296 101296 0 0.0
text 550256 550280 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 909259 909275 16 0.0
bss 117300 117300 0 0.0
rodata 103392 103392 0 0.0
text 611188 611212 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 820418 820450 32 0.0
bss 115220 115220 0 0.0
rodata 96620 96620 0 0.0
text 528164 528188 24 0.0
pigweed-app nrf52840dk_nrf52840 (read/write) 542351 542351 0 0.0
bss 52588 52588 0 0.0
rodata 50668 50668 0 0.0
text 376892 376892 0 0.0
pump-app nrf52840dk_nrf52840 (read/write) 910523 910555 32 0.0
bss 117060 117060 0 0.0
rodata 103608 103608 0 0.0
text 612404 612428 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 907339 907355 16 0.0
bss 117088 117088 0 0.0
rodata 102864 102864 0 0.0
text 609936 609960 24 0.0
shell nrf52840dk_nrf52840 (read/write) 797935 797951 16 0.0
bss 109768 109768 0 0.0
rodata 78148 78148 0 0.0
text 533508 533532 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 710750 710766 16 0.0
bss 107656 107656 0 0.0
rodata 72448 72448 0 0.0
text 451188 451212 24 0.0
p6 all-clusters-app default (read/write) 2401656 2401656 0 0.0
.bss 116804 116804 0 0.0
.data 2592 2592 0 0.0
.text 1359920 1359920 0 0.0
light-app default (read/write) 2323680 2323680 0 0.0
.bss 105672 105672 0 0.0
.data 2384 2384 0 0.0
.text 1281944 1281944 0 0.0
lock-app default (read/write) 2295904 2295904 0 0.0
.bss 104552 104552 0 0.0
.data 2336 2336 0 0.0
.text 1254168 1254168 0 0.0
qpg lighting-app qpg6105+debug (read only) 533192 533192 0 0.0
(read/write) 146936 146936 0 0.0
.bss 86624 86624 0 0.0
.data 1004 1004 0 0.0
.text 527872 527872 0 0.0
lock-app qpg6105+debug (read only) 504968 504968 0 0.0
(read/write) 146940 146940 0 0.0
.bss 85760 85760 0 0.0
.data 952 952 0 0.0
.text 499648 499648 0 0.0
persistent-storage-app qpg6105+debug (read only) 106448 106448 0 0.0
(read/write) 146938 146938 0 0.0
.bss 36146 36146 0 0.0
.data 288 288 0 0.0
.text 101128 101128 0 0.0
telink lighting-app tlsr9518adk80d (read/write) 834522 834522 0 0.0
bss 86924 86924 0 0.0
noinit 37160 37160 0 0.0
text 582766 582766 0 0.0

@bzbarsky-apple bzbarsky-apple force-pushed the fix-unsafe-strncpy-openthread branch 2 times, most recently from 7853ccf to 4bad9d5 Compare January 10, 2022 16:33
@github-actions
Copy link

github-actions bot commented Jan 10, 2022

PR #13392: Size comparison from 08753ba to 4bad9d5

Increases (14 builds for efr32, k32w, nrfconnect)
platform target config section 08753ba 4bad9d5 change % change
efr32 lighting-app BRD4161A (read only) 829244 829276 32 0.0
.text 829236 829268 32 0.0
BRD4161A+rpc (read only) 816888 816920 32 0.0
.text 816880 816912 32 0.0
window-app BRD4161A (read only) 802708 802724 16 0.0
.text 802700 802716 16 0.0
k32w light k32w061+release (read/write) 655308 655324 16 0.0
.text 570884 570900 16 0.0
lock k32w061+release (read/write) 659632 659664 32 0.0
.text 574892 574924 32 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 937115 937147 32 0.0
text 633332 633356 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 923527 923543 16 0.0
text 628644 628668 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 848110 848126 16 0.0
text 550268 550292 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 909259 909291 32 0.0
text 611196 611220 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 820434 820450 16 0.0
text 528172 528196 24 0.0
pump-app nrf52840dk_nrf52840 (read/write) 910539 910555 16 0.0
text 612412 612436 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 907339 907371 32 0.0
text 609944 609968 24 0.0
shell nrf52840dk_nrf52840 (read/write) 797935 797951 16 0.0
text 533508 533532 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 710750 710766 16 0.0
text 451188 451212 24 0.0
Full report (31 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
platform target config section 08753ba 4bad9d5 change % change
efr32 lighting-app BRD4161A (read only) 829244 829276 32 0.0
(read/write) 126996 126996 0 0.0
.bss 125120 125120 0 0.0
.data 1876 1876 0 0.0
.text 829236 829268 32 0.0
BRD4161A+rpc (read only) 816888 816920 32 0.0
(read/write) 143656 143656 0 0.0
.bss 141680 141680 0 0.0
.data 1976 1976 0 0.0
.text 816880 816912 32 0.0
window-app BRD4161A (read only) 802708 802724 16 0.0
(read/write) 125936 125936 0 0.0
.bss 124104 124104 0 0.0
.data 1832 1832 0 0.0
.text 802700 802716 16 0.0
esp32 all-clusters-app c3devkit (read only) 891640 891640 0 0.0
(read/write) 1314026 1314026 0 0.0
.dram0.bss 69480 69480 0 0.0
.dram0.data 14236 14236 0 0.0
.flash.rodata 177248 177248 0 0.0
.flash.text 891640 891640 0 0.0
.iram0.text 62254 62254 0 0.0
m5stack (read only) 951627 951627 0 0.0
(read/write) 445604 445604 0 0.0
.dram0.bss 73968 73968 0 0.0
.dram0.data 34064 34064 0 0.0
.flash.rodata 206564 206564 0 0.0
.flash.text 946243 946243 0 0.0
.iram0.text 122671 122671 0 0.0
k32w light k32w061+release (read/write) 655308 655324 16 0.0
.bss 76776 76776 0 0.0
.data 1848 1848 0 0.0
.text 570884 570900 16 0.0
lock k32w061+release (read/write) 659632 659664 32 0.0
.bss 77072 77072 0 0.0
.data 1868 1868 0 0.0
.text 574892 574924 32 0.0
linux chip-tool-ipv6only arm64 (read only) 7105196 7105196 0 0.0
(read/write) 327009 327009 0 0.0
.bss 54865 54865 0 0.0
.data 1096 1096 0 0.0
.data.rel.ro 209392 209392 0 0.0
.dynamic 560 560 0 0.0
.got 57968 57968 0 0.0
.init 24 24 0 0.0
.init_array 168 168 0 0.0
.rodata 388900 388900 0 0.0
.text 6019748 6019748 0 0.0
thermostat-no-ble arm64 (read only) 2033724 2033724 0 0.0
(read/write) 145089 145089 0 0.0
.bss 64657 64657 0 0.0
.data 880 880 0 0.0
.data.rel.ro 72624 72624 0 0.0
.dynamic 560 560 0 0.0
.got 4000 4000 0 0.0
.init 24 24 0 0.0
.init_array 296 296 0 0.0
.rodata 128988 128988 0 0.0
.text 1691088 1691088 0 0.0
mbed all-clusters-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2348240 2348240 0 0.0
.bss 188724 188724 0 0.0
.data 5312 5312 0 0.0
.text 1310816 1310816 0 0.0
lighting-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2330752 2330752 0 0.0
.bss 180544 180544 0 0.0
.data 5552 5552 0 0.0
.text 1293352 1293352 0 0.0
lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2303904 2303904 0 0.0
.bss 179592 179592 0 0.0
.data 5544 5544 0 0.0
.text 1266504 1266504 0 0.0
pigweed-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 1140008 1140008 0 0.0
.bss 11756 11756 0 0.0
.data 4368 4368 0 0.0
.text 103392 103392 0 0.0
shell CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2054256 2054256 0 0.0
.bss 157060 157060 0 0.0
.data 4864 4864 0 0.0
.text 1016856 1016856 0 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 937115 937147 32 0.0
bss 118112 118112 0 0.0
rodata 108120 108120 0 0.0
text 633332 633356 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 923527 923543 16 0.0
bss 115156 115156 0 0.0
rodata 101548 101548 0 0.0
text 628644 628668 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 848110 848126 16 0.0
bss 116004 116004 0 0.0
rodata 101296 101296 0 0.0
text 550268 550292 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 909259 909291 32 0.0
bss 117300 117300 0 0.0
rodata 103392 103392 0 0.0
text 611196 611220 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 820434 820450 16 0.0
bss 115220 115220 0 0.0
rodata 96620 96620 0 0.0
text 528172 528196 24 0.0
pigweed-app nrf52840dk_nrf52840 (read/write) 542351 542351 0 0.0
bss 52588 52588 0 0.0
rodata 50668 50668 0 0.0
text 376892 376892 0 0.0
pump-app nrf52840dk_nrf52840 (read/write) 910539 910555 16 0.0
bss 117060 117060 0 0.0
rodata 103608 103608 0 0.0
text 612412 612436 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 907339 907371 32 0.0
bss 117088 117088 0 0.0
rodata 102864 102864 0 0.0
text 609944 609968 24 0.0
shell nrf52840dk_nrf52840 (read/write) 797935 797951 16 0.0
bss 109768 109768 0 0.0
rodata 78148 78148 0 0.0
text 533508 533532 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 710750 710766 16 0.0
bss 107656 107656 0 0.0
rodata 72448 72448 0 0.0
text 451188 451212 24 0.0
p6 all-clusters-app default (read/write) 2401288 2401288 0 0.0
.bss 116812 116812 0 0.0
.data 2592 2592 0 0.0
.text 1359552 1359552 0 0.0
light-app default (read/write) 2323696 2323696 0 0.0
.bss 105672 105672 0 0.0
.data 2384 2384 0 0.0
.text 1281960 1281960 0 0.0
lock-app default (read/write) 2295920 2295920 0 0.0
.bss 104552 104552 0 0.0
.data 2336 2336 0 0.0
.text 1254184 1254184 0 0.0
qpg lighting-app qpg6105+debug (read only) 533208 533208 0 0.0
(read/write) 146936 146936 0 0.0
.bss 86624 86624 0 0.0
.data 1004 1004 0 0.0
.text 527888 527888 0 0.0
lock-app qpg6105+debug (read only) 504984 504984 0 0.0
(read/write) 146940 146940 0 0.0
.bss 85760 85760 0 0.0
.data 952 952 0 0.0
.text 499664 499664 0 0.0
persistent-storage-app qpg6105+debug (read only) 106448 106448 0 0.0
(read/write) 146938 146938 0 0.0
.bss 36146 36146 0 0.0
.data 288 288 0 0.0
.text 101128 101128 0 0.0
telink lighting-app tlsr9518adk80d (read/write) 834522 834522 0 0.0
bss 86924 86924 0 0.0
noinit 37160 37160 0 0.0
text 582766 582766 0 0.0

@bzbarsky-apple bzbarsky-apple force-pushed the fix-unsafe-strncpy-openthread branch from 4bad9d5 to 26b2267 Compare January 10, 2022 18:28
@github-actions
Copy link

github-actions bot commented Jan 10, 2022

PR #13392: Size comparison from 5053f20 to 26b2267

Increases (14 builds for efr32, k32w, nrfconnect)
platform target config section 5053f20 26b2267 change % change
efr32 lighting-app BRD4161A (read only) 829348 829380 32 0.0
.text 829340 829372 32 0.0
BRD4161A+rpc (read only) 816992 817024 32 0.0
.text 816984 817016 32 0.0
window-app BRD4161A (read only) 802812 802844 32 0.0
.text 802804 802836 32 0.0
k32w light k32w061+release (read/write) 655396 655428 32 0.0
.text 570972 571004 32 0.0
lock k32w061+release (read/write) 659736 659752 16 0.0
.text 574996 575012 16 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 937247 937279 32 0.0
text 633432 633456 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 923655 923671 16 0.0
text 628744 628768 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 848238 848254 16 0.0
text 550368 550392 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 909391 909423 32 0.0
text 611296 611320 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 820562 820578 16 0.0
text 528272 528296 24 0.0
pump-app nrf52840dk_nrf52840 (read/write) 910667 910699 32 0.0
text 612512 612536 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 907471 907503 32 0.0
text 610044 610068 24 0.0
shell nrf52840dk_nrf52840 (read/write) 798063 798095 32 0.0
text 533608 533632 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 710882 710914 32 0.0
text 451288 451312 24 0.0
Full report (31 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
platform target config section 5053f20 26b2267 change % change
efr32 lighting-app BRD4161A (read only) 829348 829380 32 0.0
(read/write) 126996 126996 0 0.0
.bss 125120 125120 0 0.0
.data 1876 1876 0 0.0
.text 829340 829372 32 0.0
BRD4161A+rpc (read only) 816992 817024 32 0.0
(read/write) 143656 143656 0 0.0
.bss 141680 141680 0 0.0
.data 1976 1976 0 0.0
.text 816984 817016 32 0.0
window-app BRD4161A (read only) 802812 802844 32 0.0
(read/write) 125936 125936 0 0.0
.bss 124104 124104 0 0.0
.data 1832 1832 0 0.0
.text 802804 802836 32 0.0
esp32 all-clusters-app c3devkit (read only) 890430 890430 0 0.0
(read/write) 1313594 1313594 0 0.0
.dram0.bss 69472 69472 0 0.0
.dram0.data 14244 14244 0 0.0
.flash.rodata 176816 176816 0 0.0
.flash.text 890430 890430 0 0.0
.iram0.text 62254 62254 0 0.0
m5stack (read only) 950555 950555 0 0.0
(read/write) 445204 445204 0 0.0
.dram0.bss 73968 73968 0 0.0
.dram0.data 34064 34064 0 0.0
.flash.rodata 206164 206164 0 0.0
.flash.text 945171 945171 0 0.0
.iram0.text 122671 122671 0 0.0
k32w light k32w061+release (read/write) 655396 655428 32 0.0
.bss 76776 76776 0 0.0
.data 1848 1848 0 0.0
.text 570972 571004 32 0.0
lock k32w061+release (read/write) 659736 659752 16 0.0
.bss 77072 77072 0 0.0
.data 1868 1868 0 0.0
.text 574996 575012 16 0.0
linux chip-tool-ipv6only arm64 (read only) 7105612 7105612 0 0.0
(read/write) 327041 327041 0 0.0
.bss 54865 54865 0 0.0
.data 1096 1096 0 0.0
.data.rel.ro 209424 209424 0 0.0
.dynamic 560 560 0 0.0
.got 57976 57976 0 0.0
.init 24 24 0 0.0
.init_array 168 168 0 0.0
.rodata 388916 388916 0 0.0
.text 6020036 6020036 0 0.0
thermostat-no-ble arm64 (read only) 2034188 2034188 0 0.0
(read/write) 145137 145137 0 0.0
.bss 64657 64657 0 0.0
.data 880 880 0 0.0
.data.rel.ro 72656 72656 0 0.0
.dynamic 560 560 0 0.0
.got 4008 4008 0 0.0
.init 24 24 0 0.0
.init_array 296 296 0 0.0
.rodata 129004 129004 0 0.0
.text 1691408 1691408 0 0.0
mbed all-clusters-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2346888 2346888 0 0.0
.bss 188716 188716 0 0.0
.data 5312 5312 0 0.0
.text 1309464 1309464 0 0.0
lighting-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2330856 2330856 0 0.0
.bss 180544 180544 0 0.0
.data 5552 5552 0 0.0
.text 1293456 1293456 0 0.0
lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2304008 2304008 0 0.0
.bss 179592 179592 0 0.0
.data 5544 5544 0 0.0
.text 1266608 1266608 0 0.0
pigweed-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 1140008 1140008 0 0.0
.bss 11756 11756 0 0.0
.data 4368 4368 0 0.0
.text 103392 103392 0 0.0
shell CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2054432 2054432 0 0.0
.bss 157060 157060 0 0.0
.data 4864 4864 0 0.0
.text 1017032 1017032 0 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 937247 937279 32 0.0
bss 118112 118112 0 0.0
rodata 108156 108156 0 0.0
text 633432 633456 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 923655 923671 16 0.0
bss 115156 115156 0 0.0
rodata 101580 101580 0 0.0
text 628744 628768 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 848238 848254 16 0.0
bss 116004 116004 0 0.0
rodata 101328 101328 0 0.0
text 550368 550392 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 909391 909423 32 0.0
bss 117300 117300 0 0.0
rodata 103428 103428 0 0.0
text 611296 611320 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 820562 820578 16 0.0
bss 115220 115220 0 0.0
rodata 96652 96652 0 0.0
text 528272 528296 24 0.0
pigweed-app nrf52840dk_nrf52840 (read/write) 542351 542351 0 0.0
bss 52588 52588 0 0.0
rodata 50668 50668 0 0.0
text 376892 376892 0 0.0
pump-app nrf52840dk_nrf52840 (read/write) 910667 910699 32 0.0
bss 117060 117060 0 0.0
rodata 103640 103640 0 0.0
text 612512 612536 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 907471 907503 32 0.0
bss 117088 117088 0 0.0
rodata 102900 102900 0 0.0
text 610044 610068 24 0.0
shell nrf52840dk_nrf52840 (read/write) 798063 798095 32 0.0
bss 109768 109768 0 0.0
rodata 78180 78180 0 0.0
text 533608 533632 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 710882 710914 32 0.0
bss 107656 107656 0 0.0
rodata 72484 72484 0 0.0
text 451288 451312 24 0.0
p6 all-clusters-app default (read/write) 2399760 2399760 0 0.0
.bss 116804 116804 0 0.0
.data 2592 2592 0 0.0
.text 1358024 1358024 0 0.0
light-app default (read/write) 2323856 2323856 0 0.0
.bss 105672 105672 0 0.0
.data 2384 2384 0 0.0
.text 1282120 1282120 0 0.0
lock-app default (read/write) 2296080 2296080 0 0.0
.bss 104552 104552 0 0.0
.data 2336 2336 0 0.0
.text 1254344 1254344 0 0.0
qpg lighting-app qpg6105+debug (read only) 533296 533296 0 0.0
(read/write) 146936 146936 0 0.0
.bss 86624 86624 0 0.0
.data 1004 1004 0 0.0
.text 527976 527976 0 0.0
lock-app qpg6105+debug (read only) 505072 505072 0 0.0
(read/write) 146940 146940 0 0.0
.bss 85760 85760 0 0.0
.data 952 952 0 0.0
.text 499752 499752 0 0.0
persistent-storage-app qpg6105+debug (read only) 106448 106448 0 0.0
(read/write) 146938 146938 0 0.0
.bss 36146 36146 0 0.0
.data 288 288 0 0.0
.text 101128 101128 0 0.0
telink lighting-app tlsr9518adk80d (read/write) 834638 834638 0 0.0
bss 86924 86924 0 0.0
noinit 37160 37160 0 0.0
text 582846 582846 0 0.0

For the three uses where we are copying data of some computed size
into a buffer, add checks that the size is not too big for the buffer
(and in particular that we will be able to null-terminate after
copying).

For the one use where we are copying the entire buffer between two
identical-sized buffers:

1) Assert that the target buffer us not smaller than the source buffer.

2) Use CopyString to ensure null-termination even if the source is not
null-terminated.
@bzbarsky-apple bzbarsky-apple force-pushed the fix-unsafe-strncpy-openthread branch from 26b2267 to 0d8fbd7 Compare January 11, 2022 16:58
@github-actions
Copy link

github-actions bot commented Jan 11, 2022

PR #13392: Size comparison from 1cbec52 to 0d8fbd7

Increases (15 builds for efr32, k32w, nrfconnect)
platform target config section 1cbec52 0d8fbd7 change % change
efr32 lighting-app BRD4161A (read only) 830240 830256 16 0.0
.text 830232 830248 16 0.0
BRD4161A+rpc (read only) 817644 817660 16 0.0
.text 817636 817652 16 0.0
window-app BRD4161A (read only) 804184 804200 16 0.0
.text 804176 804192 16 0.0
k32w light k32w061+release (read/write) 656348 656380 32 0.0
.text 571872 571904 32 0.0
lock k32w061+release (read/write) 660688 660720 32 0.0
.text 575896 575928 32 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 939279 939295 16 0.0
text 634088 634112 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 924747 924763 16 0.0
text 629440 629464 24 0.0
nrf52840dongle_nrf52840 (read/write) 989939 989971 32 0.0
text 666284 666308 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 849138 849154 16 0.0
text 551008 551032 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 911551 911567 16 0.0
text 612080 612104 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 821590 821606 16 0.0
text 529040 529064 24 0.0
pump-app nrf52840dk_nrf52840 (read/write) 912831 912863 32 0.0
text 613340 613364 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 909631 909647 16 0.0
text 610828 610852 24 0.0
shell nrf52840dk_nrf52840 (read/write) 798391 798423 32 0.0
text 533832 533856 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 711206 711238 32 0.0
text 451512 451536 24 0.0
Full report (32 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
platform target config section 1cbec52 0d8fbd7 change % change
efr32 lighting-app BRD4161A (read only) 830240 830256 16 0.0
(read/write) 127300 127300 0 0.0
.bss 125420 125420 0 0.0
.data 1880 1880 0 0.0
.text 830232 830248 16 0.0
BRD4161A+rpc (read only) 817644 817660 16 0.0
(read/write) 143960 143960 0 0.0
.bss 141980 141980 0 0.0
.data 1980 1980 0 0.0
.text 817636 817652 16 0.0
window-app BRD4161A (read only) 804184 804200 16 0.0
(read/write) 126008 126008 0 0.0
.bss 124168 124168 0 0.0
.data 1836 1836 0 0.0
.text 804176 804192 16 0.0
esp32 all-clusters-app c3devkit (read only) 898316 898316 0 0.0
(read/write) 1316082 1316082 0 0.0
.dram0.bss 70168 70168 0 0.0
.dram0.data 14212 14212 0 0.0
.flash.rodata 178200 178200 0 0.0
.flash.text 898316 898316 0 0.0
.iram0.text 62056 62056 0 0.0
m5stack (read only) 959427 959427 0 0.0
(read/write) 448536 448536 0 0.0
.dram0.bss 74656 74656 0 0.0
.dram0.data 34064 34064 0 0.0
.flash.rodata 207688 207688 0 0.0
.flash.text 954043 954043 0 0.0
.iram0.text 123399 123399 0 0.0
k32w light k32w061+release (read/write) 656348 656380 32 0.0
.bss 76824 76824 0 0.0
.data 1852 1852 0 0.0
.text 571872 571904 32 0.0
lock k32w061+release (read/write) 660688 660720 32 0.0
.bss 77120 77120 0 0.0
.data 1872 1872 0 0.0
.text 575896 575928 32 0.0
linux chip-tool-ipv6only arm64 (read only) 7114060 7114060 0 0.0
(read/write) 327473 327473 0 0.0
.bss 54865 54865 0 0.0
.data 1096 1096 0 0.0
.data.rel.ro 209624 209624 0 0.0
.dynamic 560 560 0 0.0
.got 58208 58208 0 0.0
.init 24 24 0 0.0
.init_array 168 168 0 0.0
.rodata 390148 390148 0 0.0
.text 6026020 6026020 0 0.0
thermostat-no-ble arm64 (read only) 2037468 2037468 0 0.0
(read/write) 145505 145505 0 0.0
.bss 64737 64737 0 0.0
.data 880 880 0 0.0
.data.rel.ro 72912 72912 0 0.0
.dynamic 560 560 0 0.0
.got 4040 4040 0 0.0
.init 24 24 0 0.0
.init_array 304 304 0 0.0
.rodata 129276 129276 0 0.0
.text 1693888 1693888 0 0.0
mbed all-clusters-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2348912 2348912 0 0.0
.bss 188876 188876 0 0.0
.data 5320 5320 0 0.0
.text 1311488 1311488 0 0.0
lighting-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2330560 2330560 0 0.0
.bss 180416 180416 0 0.0
.data 5552 5552 0 0.0
.text 1293160 1293160 0 0.0
lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2303784 2303784 0 0.0
.bss 179456 179456 0 0.0
.data 5544 5544 0 0.0
.text 1266384 1266384 0 0.0
pigweed-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 1139712 1139712 0 0.0
.bss 11756 11756 0 0.0
.data 4368 4368 0 0.0
.text 103096 103096 0 0.0
shell CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2054232 2054232 0 0.0
.bss 156876 156876 0 0.0
.data 4864 4864 0 0.0
.text 1016832 1016832 0 0.0
nrfconnect lighting-app nrf52840dk_nrf52840 (read/write) 939279 939295 16 0.0
bss 119284 119284 0 0.0
rodata 108332 108332 0 0.0
text 634088 634112 24 0.0
nrf52840dk_nrf52840+rpc (read/write) 924747 924763 16 0.0
bss 116328 116328 0 0.0
rodata 100784 100784 0 0.0
text 629440 629464 24 0.0
nrf52840dongle_nrf52840 (read/write) 989939 989971 32 0.0
bss 122128 122128 0 0.0
rodata 113084 113084 0 0.0
text 666284 666308 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 849138 849154 16 0.0
bss 116072 116072 0 0.0
rodata 101508 101508 0 0.0
text 551008 551032 24 0.0
lock-app nrf52840dk_nrf52840 (read/write) 911551 911567 16 0.0
bss 118472 118472 0 0.0
rodata 103604 103604 0 0.0
text 612080 612104 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 821590 821606 16 0.0
bss 115288 115288 0 0.0
rodata 96832 96832 0 0.0
text 529040 529064 24 0.0
pigweed-app nrf52840dk_nrf52840 (read/write) 541835 541835 0 0.0
bss 52588 52588 0 0.0
rodata 50104 50104 0 0.0
text 376940 376940 0 0.0
pump-app nrf52840dk_nrf52840 (read/write) 912831 912863 32 0.0
bss 118232 118232 0 0.0
rodata 103820 103820 0 0.0
text 613340 613364 24 0.0
pump-controller-app nrf52840dk_nrf52840 (read/write) 909631 909647 16 0.0
bss 118260 118260 0 0.0
rodata 103076 103076 0 0.0
text 610828 610852 24 0.0
shell nrf52840dk_nrf52840 (read/write) 798391 798423 32 0.0
bss 109776 109776 0 0.0
rodata 78284 78284 0 0.0
text 533832 533856 24 0.0
nrf5340dk_nrf5340_cpuapp (read/write) 711206 711238 32 0.0
bss 107664 107664 0 0.0
rodata 72584 72584 0 0.0
text 451512 451536 24 0.0
p6 all-clusters-app default (read/write) 2403200 2403200 0 0.0
.bss 117148 117148 0 0.0
.data 2592 2592 0 0.0
.text 1361464 1361464 0 0.0
light-app default (read/write) 2325088 2325088 0 0.0
.bss 105728 105728 0 0.0
.data 2384 2384 0 0.0
.text 1283352 1283352 0 0.0
lock-app default (read/write) 2297320 2297320 0 0.0
.bss 104608 104608 0 0.0
.data 2344 2344 0 0.0
.text 1255584 1255584 0 0.0
qpg lighting-app qpg6105+debug (read only) 534060 534060 0 0.0
(read/write) 146940 146940 0 0.0
.bss 86672 86672 0 0.0
.data 1008 1008 0 0.0
.text 528740 528740 0 0.0
lock-app qpg6105+debug (read only) 505980 505980 0 0.0
(read/write) 146936 146936 0 0.0
.bss 85808 85808 0 0.0
.data 956 956 0 0.0
.text 500660 500660 0 0.0
persistent-storage-app qpg6105+debug (read only) 106448 106448 0 0.0
(read/write) 146938 146938 0 0.0
.bss 36146 36146 0 0.0
.data 288 288 0 0.0
.text 101128 101128 0 0.0
telink lighting-app tlsr9518adk80d (read/write) 835878 835878 0 0.0
bss 86976 86976 0 0.0
noinit 37160 37160 0 0.0
text 583752 583752 0 0.0

@bzbarsky-apple bzbarsky-apple merged commit 68df85c into project-chip:master Jan 11, 2022
@bzbarsky-apple bzbarsky-apple deleted the fix-unsafe-strncpy-openthread branch January 11, 2022 18:36
selissia pushed a commit to selissia/connectedhomeip that referenced this pull request Jan 28, 2022
)

For the three uses where we are copying data of some computed size
into a buffer, add checks that the size is not too big for the buffer
(and in particular that we will be able to null-terminate after
copying).

For the one use where we are copying the entire buffer between two
identical-sized buffers:

1) Assert that the target buffer us not smaller than the source buffer.

2) Use CopyString to ensure null-termination even if the source is not
null-terminated.
step0035 pushed a commit to hank820/connectedhomeip that referenced this pull request Feb 8, 2022
)

For the three uses where we are copying data of some computed size
into a buffer, add checks that the size is not too big for the buffer
(and in particular that we will be able to null-terminate after
copying).

For the one use where we are copying the entire buffer between two
identical-sized buffers:

1) Assert that the target buffer us not smaller than the source buffer.

2) Use CopyString to ensure null-termination even if the source is not
null-terminated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants