mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 12:55:14 +03:00
Don't accept fancy lookin letters.
Backstory, Unified configs mean we can embed arbitrary text into the firmware, what is one source of text? Project Gutenberg! I tried attaching a snippet of the text into the config (as comments, I am a careful deviant) and ended up learning a little about how text is encoded and handled these days. Given a character with a value higher than 1 byte, the value gets cropped off, so 0x2018 would get flashed as 0x18, and would fail validation, because we'd be checking 0x2018 against 0x18 Asking Notepad++ to convert the document to ANSI was no good either, it decided to use Code page 1252, which still has fancy quotes, and when loaded into the configurator, instead of 0x92, it'd be converted to a replacement character FFFD if you want to look something up.
This commit is contained in:
parent
074bb46f78
commit
96619a4b58
2 changed files with 17 additions and 4 deletions
|
@ -587,6 +587,12 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
self.flashingMessage(i18n.getMessage('firmwareFlasherFirmwareLocalLoaded', self.parsed_hex.bytes_total), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
}
|
||||
}
|
||||
function checkAsciiLimits(input) {
|
||||
for (let i=0; i < input.length; i++) {
|
||||
if (input.charCodeAt(i) > 127) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// UI Hooks
|
||||
$('a.load_file').click(function () {
|
||||
self.enableFlashing(false);
|
||||
|
@ -641,10 +647,14 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
});
|
||||
} else {
|
||||
clearBufferedFirmware();
|
||||
self.unifiedTargetConfig = e.target.result;
|
||||
self.unifiedTargetConfigName = file.name;
|
||||
self.isConfigLocal = true;
|
||||
flashingMessageLocal();
|
||||
if (checkAsciiLimits(e.target.result)) {
|
||||
self.unifiedTargetConfig = e.target.result;
|
||||
self.unifiedTargetConfigName = file.name;
|
||||
self.isConfigLocal = true;
|
||||
flashingMessageLocal();
|
||||
} else {
|
||||
self.flashingMessage('firmwareFlasherConfigCorrupted', self.FLASH_MESSAGE_TYPES.INVALID);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue