martin-ger / uMQTTBroker

MQTT Broker library for ESP8266 Arduino
MIT License
443 stars 105 forks source link

bug: discards connections if user,pass empty but non NULL; possible FIX #43

Open aldoaldoaldo opened 4 years ago

aldoaldoaldo commented 4 years ago

The caller may set the user/pass flag to "present" but can meantime pass strings with just \0 so basically empty, even if non NULL. This happens for example when you use Arduino Strings and you have user="" and you use user.c_str() with a MQTT client such as PubSubClient for example (it is compact so I believe widely used). If you do this with Mosquito, it goes on without problems. If you do this with current uMQTTBroker, it discards you and you can take some time to figure out what is happening (see #40 :-) !!!! ).

A possible fix would be to REMOVE the strict check that you are doing. If Mosquito on PC does not check for this, why does a small ESP library should waste precious bytes to do these useless verification? The application using the library can also verify these user/pass if needed.

aldoaldoaldo commented 4 years ago

I copy the current workaround from the other issue I closed. Workaround for PubSubClient users that love to use Strings to store their parameters:


    const char* user=NULL;
    const char* pass=NULL;
    if ((mqtt_user!="") && (mqtt_pass!="")) {
      user=mqtt_user.c_str();
      pass=mqtt_pass.c_str();
    }
    if (client.connect(clientId.c_str(),user,pass)) {
....