Skip to content

Commit 79568a3

Browse files
OTA Updater better error codes on OOS (earlephilhower#2793)
Fixes earlephilhower#2785. Thanks @donmsmall!
1 parent b506c01 commit 79568a3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libraries/Updater/src/Updater.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,18 @@ bool UpdaterClass::begin(size_t size, int command) {
9797
_md5 = MD5Builder();
9898

9999
if (command == U_FLASH) {
100+
// Basic sanity, if it's larger than entire FS then it can't possibly succeed
101+
if (&_FS_start + size > &_FS_end) {
102+
_setError(UPDATE_ERROR_SPACE);
103+
return false;
104+
}
100105
LittleFS.begin();
101106
_fp = LittleFS.open("firmware.bin", "w+");
102107
if (!_fp) {
103108
#ifdef DEBUG_UPDATER
104109
DEBUG_UPDATER.println(F("[begin] unable to create file"));
105110
#endif
111+
_setError(UPDATE_ERROR_SPACE);
106112
return false;
107113
}
108114
updateStartAddress = 0; // Not used
@@ -288,6 +294,7 @@ bool UpdaterClass::end(bool evenIfRemaining) {
288294
bool UpdaterClass::_writeBuffer() {
289295
if (_command == U_FLASH) {
290296
if (_bufferLen != _fp.write(_buffer, _bufferLen)) {
297+
_setError(UPDATE_ERROR_SPACE);
291298
return false;
292299
}
293300
} else {

0 commit comments

Comments
 (0)