From d3f5b9b6ed42ac47ac09d0bdaf9dd4662511ca40 Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 13 Aug 2024 04:29:18 -0700 Subject: [PATCH] fix(ota): Wrap espota --auth flag in quotes (#10126) When performing an "OTA" upload via a network port, the user may configure the sketch to require an authentication password. Arduino IDE presents a "Configure and Upload" dialog when the user triggers an upload to a network port. The user can provide the authentication password via the field in that dialog. The `upload.field.password` platform property is then set to the value provided by the user. The platform uses the `tools.esp_ota.upload.pattern` command template to pass this value to the espota upload tool via the tool's `--auth` flag. Since the value of the `upload.field.password` platform property is set by the user via a free text field, it might contain any characters. Since some characters (e.g., spaces) can be problematic in a command line, it is essential to wrap it in quotes. This was done for the Arduino IDE 1.x variant of the command template, but that was not ported when the pluggable discovery variant of the command pattern was defined. This causes a spurious failure of the OTA upload process if the user provides an authentication password that contains problematic characters. For example: ``` "C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.4\tools\espota.exe" \ -r -i 192.168.254.145 \ -p 3232 --auth=foo bar \ -f "C:\Users\per\AppData\Local\Temp\arduino\sketches\E2D807FABB134A2A60A1B9C7D14FE02B/11973.ino.bin" usage: espota.exe [-h] [-i ESP_IP] [-I HOST_IP] [-p ESP_PORT] [-P HOST_PORT] [-a AUTH] [-f FILE] [-s] [-d] [-r] [-t TIMEOUT] espota.exe: error: unrecognized arguments: bar Failed uploading: uploading error: exit status 2 ``` This is prevented by wrapping the `--auth` flag in quotes: ``` "C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.4\tools\espota.exe" \ a-r -i 192.168.254.145 \ -p 3232 "--auth=foo bar" \ -f "C:\Users\per\AppData\Local\Temp\arduino\sketches\E2D807FABB134A2A60A1B9C7D14FE02B/11973.ino.bin" Sending invitation to 192.168.254.145 Authenticating...OK Uploading: [ ] 0% ``` --- platform.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.txt b/platform.txt index 5ed92d4923f..f3eb69f0862 100644 --- a/platform.txt +++ b/platform.txt @@ -321,7 +321,7 @@ tools.esptool_py.upload.network_pattern={network_cmd} -i "{serial.port}" -p "{ne tools.esp_ota.upload.protocol=network tools.esp_ota.upload.field.password=Password tools.esp_ota.upload.field.password.secret=true -tools.esp_ota.upload.pattern={cmd} -i {upload.port.address} -p {upload.port.properties.port} --auth={upload.field.password} -f "{build.path}/{build.project_name}.bin" +tools.esp_ota.upload.pattern={cmd} -i {upload.port.address} -p {upload.port.properties.port} "--auth={upload.field.password}" -f "{build.path}/{build.project_name}.bin" ## Upload Sketch Through DFU OTA ## -------------------------------------------