Skip to content

Commit

Permalink
Fixed WS281x output on ESP32
Browse files Browse the repository at this point in the history
Fixed potential out-of-bounds write in MQTT
Fixed IR pin not changeable if IR disabled
Fixed XML API <wv> containing -1 on Manual only RGBW mode (see Aircoookie#888, Aircoookie#1783)
  • Loading branch information
Aircoookie committed May 20, 2021
1 parent 1617658 commit 371c4e0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

### Builds after release 0.12.0

#### Build 2105200

- Fixed WS281x output on ESP32
- Fixed potential out-of-bounds write in MQTT
- Fixed IR pin not changeable if IR disabled
- Fixed XML API <wv> containing -1 on Manual only RGBW mode (see #888, #1783)

#### Build 2105171

- Always copy MQTT payloads to prevent non-0-terminated strings
Expand Down
6 changes: 3 additions & 3 deletions wled00/bus_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ class PolyBus {
}

//gives back the internal type index (I_XX_XXX_X above) for the input
static uint8_t getI(uint8_t busType, uint8_t* pins, uint8_t num = 0, bool rgbwOverride = false) {
static uint8_t getI(uint8_t busType, uint8_t* pins, uint8_t num = 0) {
if (!IS_DIGITAL(busType)) return I_NONE;
if (IS_2PIN(busType)) { //SPI LED chips
bool isHSPI = false;
Expand All @@ -863,7 +863,7 @@ class PolyBus {
switch (busType) {
case TYPE_WS2812_RGB:
case TYPE_WS2812_WWA:
return (rgbwOverride ? I_8266_U0_NEO_4 : I_8266_U0_NEO_3) + offset;
return I_8266_U0_NEO_3 + offset;
case TYPE_SK6812_RGBW:
return I_8266_U0_NEO_4 + offset;
case TYPE_WS2811_400KHZ:
Expand All @@ -877,7 +877,7 @@ class PolyBus {
switch (busType) {
case TYPE_WS2812_RGB:
case TYPE_WS2812_WWA:
return (rgbwOverride ? I_32_R0_NEO_3 : I_32_R0_NEO_4) + offset;
return I_32_R0_NEO_3 + offset;
case TYPE_SK6812_RGBW:
return I_32_R0_NEO_4 + offset;
case TYPE_WS2811_400KHZ:
Expand Down
4 changes: 0 additions & 4 deletions wled00/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(macroLongPress,hw_btn_ins_0_macros[1]);
CJSON(macroDoublePress, hw_btn_ins_0_macros[2]);

#ifndef WLED_DISABLE_INFRARED
int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
if (hw_ir_pin > -2) {
if (pinManager.allocatePin(hw_ir_pin,false)) {
Expand All @@ -149,7 +148,6 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
irPin = -1;
}
}
#endif
CJSON(irEnabled, hw["ir"]["type"]);

JsonObject relay = hw[F("relay")];
Expand Down Expand Up @@ -508,11 +506,9 @@ void serializeConfig() {
hw_btn_ins_0_macros.add(macroLongPress);
hw_btn_ins_0_macros.add(macroDoublePress);

#ifndef WLED_DISABLE_INFRARED
JsonObject hw_ir = hw.createNestedObject("ir");
hw_ir["pin"] = irPin;
hw_ir[F("type")] = irEnabled; // the byte 'irEnabled' does contain the IR-Remote Type ( 0=disabled )
#endif

JsonObject hw_relay = hw.createNestedObject(F("relay"));
hw_relay["pin"] = rlyPin;
Expand Down
2 changes: 1 addition & 1 deletion wled00/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
}
//make a copy of the payload to 0-terminate it
char* payloadStr = new char[len+1];
if (payloadStr == nullptr) return; //no mem
strncpy(payloadStr, payload, len);
payloadStr[len] = '\0';
if (payloadStr == nullptr) return; //no mem
DEBUG_PRINTLN(payloadStr);

size_t topicPrefixLen = strlen(mqttDeviceTopic);
Expand Down
4 changes: 0 additions & 4 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
int t = 0;

if (rlyPin>=0 && pinManager.isPinAllocated(rlyPin)) pinManager.deallocatePin(rlyPin);
#ifndef WLED_DISABLE_INFRARED
if (irPin>=0 && pinManager.isPinAllocated(irPin)) pinManager.deallocatePin(irPin);
#endif
if (btnPin>=0 && pinManager.isPinAllocated(btnPin)) pinManager.deallocatePin(btnPin);
//TODO remove all busses, but not in this system call
//busses->removeAll();
Expand Down Expand Up @@ -128,14 +126,12 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
if (t > 0 && t <= MAX_LEDS) ledCount = t;

// upate other pins
#ifndef WLED_DISABLE_INFRARED
int hw_ir_pin = request->arg(F("IR")).toInt();
if (pinManager.isPinOk(hw_ir_pin) && pinManager.allocatePin(hw_ir_pin,false)) {
irPin = hw_ir_pin;
} else {
irPin = -1;
}
#endif

int hw_rly_pin = request->arg(F("RL")).toInt();
if (pinManager.allocatePin(hw_rly_pin,true)) {
Expand Down
8 changes: 6 additions & 2 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2105171
#define VERSION 2105200

//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG
Expand Down Expand Up @@ -204,7 +204,11 @@ WLED_GLOBAL bool rlyMde _INIT(true);
WLED_GLOBAL bool rlyMde _INIT(RLYMDE);
#endif
#ifndef IRPIN
WLED_GLOBAL int8_t irPin _INIT(4);
#ifdef WLED_DISABLE_INFRARED
WLED_GLOBAL int8_t irPin _INIT(-1);
#else
WLED_GLOBAL int8_t irPin _INIT(4);
#endif
#else
WLED_GLOBAL int8_t irPin _INIT(IRPIN);
#endif
Expand Down
2 changes: 1 addition & 1 deletion wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void XML_response(AsyncWebServerRequest *request, char* dest)
oappend(SET_F("</ix><fp>"));
oappendi(effectPalette);
oappend(SET_F("</fp><wv>"));
if (strip.rgbwMode) {
if (strip.isRgbw) {
oappendi(col[3]);
} else {
oappend("-1");
Expand Down

0 comments on commit 371c4e0

Please sign in to comment.