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 Updater potential overflow, add host tests #6954

Merged
merged 5 commits into from
Jan 9, 2020

Conversation

earlephilhower
Copy link
Collaborator

Fixes #4674

The Updater class could, when exactly 4K bytes were in the buffer but
not yet written to flash, allow overwriting data written to it beyond
the passed-in size parameter.

Fix per @jason-but's suggestion, and add a host test (plus minor changes
to Updater code to support host testing).

Fixes esp8266#4674

The Updater class could, when exactly 4K bytes were in the buffer but
not yet written to flash, allow overwriting data written to it beyond
the passed-in size parameter.

Fix per @jason-but's suggestion, and add a host test (plus minor changes
to Updater code to support host testing).
@earlephilhower earlephilhower added this to the 2.7.0 milestone Dec 28, 2019
Copy link
Collaborator

@mcspr mcspr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just test concerns)
Maybe use a different approach for test here? For example:

diff --git a/tests/host/Makefile b/tests/host/Makefile
index 119e8f79..f6361f36 100644
--- a/tests/host/Makefile
+++ b/tests/host/Makefile
@@ -6,6 +6,7 @@ LIBRARIES_PATH := ../../libraries
 FORCE32 ?= 1
 OPTZ ?= -Os
 V ?= 0
+DEFSYM_FS ?= -Wl,--defsym,_FS_start=0x40300000 -Wl,--defsym,_FS_end=0x411FA000 -Wl,--defsym,_FS_page=0x100 -Wl,--defsym,_FS_block=0x2000 -Wl,--defsym,_EEPROM_start=0x411fb000

 MAKEFILE = $(word 1, $(MAKEFILE_LIST))

@@ -236,7 +237,7 @@ $(BINDIR)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE)
        ranlib -c $@

 $(OUTPUT_BINARY): $(CPP_OBJECTS_TESTS) $(BINDIR)/core.a
-       $(VERBLD) $(CXX) $(LDFLAGS) $^ -o $@
+       $(VERBLD) $(CXX) $(DEFSYM_FS) $(LDFLAGS) $^ -o $@

 #################################################
 # building ino sources

Now we have FS... as addresses, without .ld
Values are from eagle.flash.16m15m.ld

wifi_set_sleep_type(NONE_SLEEP_T);
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be defined in the user_interface.cpp mock to avoid ifndef?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually is defined there already, but unfortunately user_interface.cpp is not for CI testing but for building host apps and including that ends up eventually requiring the whole host app sources (with its own main, etc.).

The host app and host tests have differing build setups and assumptions (and goals, obviously). It's probably possible to refactor them completely to avoid the duplication here, but I'm not so sure this is the right time for it (3.0.0-ish feels right).

cores/esp8266/Updater.cpp Outdated Show resolved Hide resolved
Per @mcspr's suggestion, we can pass in fake link symbols allowing
Updater to take the address of `_FS_start`/etc. even when building on
the host for testing.

There is still a single remaining wifi_set_power_mode ifdef'd and a
duplication of the digitalWrite/pinMode for testing vs. host building.
@earlephilhower earlephilhower merged commit 5bc3079 into esp8266:master Jan 9, 2020
@earlephilhower earlephilhower deleted the updater-size-check branch January 9, 2020 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESP8266 Updater class does not honour size parameter in begin(size)
4 participants