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

Add some better memory safety in discovery controller code. #8281

Merged

Conversation

bzbarsky-apple
Copy link
Contributor

Instead of assuming that subclasses give us a buffer of size at least CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES, just enforce that via the type system.

Also switch to ranged for loops over the resulting buffers.

The changes to Span.h are for two reasons:

  1. To support ranged for over a FixedSpan.
  2. To disallow constructing a FixedSpan from a buffer known to be too small.

Problem

Code makes assumptions about buffer sizes that are not enforced.

Change overview

Enforce assumptions through type system.

Testing

Compiles and passes CI. Should be no behavior changes.

Instead of assuming that subclasses give us a buffer of size at least CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES, just enforce that via the type system.

Also switch to ranged for loops over the resulting buffers.

The changes to Span.h are for two reasons:

1) To support ranged for over a FixedSpan.
2) To disallow constructing a FixedSpan from a buffer known to be too small.
@bzbarsky-apple bzbarsky-apple force-pushed the better-typesafety-discovery branch from e739573 to 553ed75 Compare July 10, 2021 19:11
@github-actions
Copy link

Size increase report for "esp32-example-build" from 0e19e0d

File Section File VM
chip-temperature-measurement-app.elf .flash.text 60 60
chip-all-clusters-app.elf .flash.text -24 -24
chip-lock-app.elf .flash.text 64 64
chip-shell.elf .flash.text 4 4
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-pigweed-app.elf and ./pull_artifact/chip-pigweed-app.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-temperature-measurement-app.elf and ./pull_artifact/chip-temperature-measurement-app.elf:

sections,vmsize,filesize
.debug_info,0,17163
.debug_str,0,890
.flash.text,60,60
.debug_abbrev,0,48
.debug_loc,0,-3
.debug_line,0,-6
[Unmapped],0,-60

Comparing ./master_artifact/chip-all-clusters-app.elf and ./pull_artifact/chip-all-clusters-app.elf:

sections,vmsize,filesize
.debug_info,0,24093
.debug_str,0,886
.xt.prop._ZN4chip6System5Mutex6UnlockEv,0,108
.debug_abbrev,0,48
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE14_LockChipStackEv,0,48
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE15_StartChipTimerEj,0,48
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE16_UnlockChipStackEv,0,48
[Unmapped],0,24
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE14_LockChipStackEv,0,12
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE15_StartChipTimerEj,0,12
.xt.prop._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE16_UnlockChipStackEv,0,12
.debug_line,0,-6
.flash.text,-24,-24
.debug_loc,0,-29
.xt.prop._ZN4chip11DeviceLayer8Internal26GenericPlatformManagerImplINS0_19PlatformManagerImplEE14_InitChipStackEv,0,-40
.xt.lit._ZN4chip11DeviceLayer8Internal35GenericPlatformManagerImpl_FreeRTOSINS0_19PlatformManagerImplEE10_PostEventEPKNS0_15ChipDeviceEventE,0,-80
.xt.lit._ZN4chip6System5Mutex6UnlockEv,0,-128

Comparing ./master_artifact/chip-lock-app.elf and ./pull_artifact/chip-lock-app.elf:

sections,vmsize,filesize
.debug_info,0,24091
.debug_str,0,890
.flash.text,64,64
.debug_abbrev,0,48
.debug_loc,0,5
.debug_line,0,-6
[Unmapped],0,-64

Comparing ./master_artifact/chip-persistent-storage.elf and ./pull_artifact/chip-persistent-storage.elf:

sections,vmsize,filesize

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize
.debug_info,0,4160
.debug_str,0,600
.flash.text,4,4
[Unmapped],0,-4


@bzbarsky-apple bzbarsky-apple merged commit 5081bbe into project-chip:master Jul 12, 2021
@bzbarsky-apple bzbarsky-apple deleted the better-typesafety-discovery branch July 12, 2021 15:53
nikita-s-wrk pushed a commit to nikita-s-wrk/connectedhomeip that referenced this pull request Sep 23, 2021
…chip#8281)

Instead of assuming that subclasses give us a buffer of size at least CHIP_DEVICE_CONFIG_MAX_DISCOVERED_NODES, just enforce that via the type system.

Also switch to ranged for loops over the resulting buffers.

The changes to Span.h are for two reasons:

1) To support ranged for over a FixedSpan.
2) To disallow constructing a FixedSpan from a buffer known to be too small.
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