Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using an address without :// mqttclient_create does not cause an error #1480

Open
michieldhonteriks opened this issue May 7, 2024 · 5 comments

Comments

@michieldhonteriks
Copy link

Describe the bug
i mistyped the address as tcp:ip:port instead of tcp://ip:port but it did not cause an error while creating the client and only a generic error while connecting.
the problem lies in the implementation where there is no error or default handling when the :// part of the string cannot be found.

To Reproduce
change the address in the publish example and remove the // after tcp
run the code

Expected behavior
the client creation function returns an error stating the address is invalid

** Environment (please complete the following information):**

  • OS: raspbian 12 (based on debian bookworm)
  • Hardware: Raspberry pi 3 B
@jumoog
Copy link
Contributor

jumoog commented May 7, 2024

Which version of the library are you using?

@michieldhonteriks
Copy link
Author

libpaho-mqtt3c.so.1.3

@jumoog
Copy link
Contributor

jumoog commented May 7, 2024

There is only a 1.3.0 version but no 1.3. Try the latest version

@michieldhonteriks
Copy link
Author

i tried it on 1.3.13 and it returns 0 on MQTTClient_create and -1 on MQTTClient_connect when the address starts with tcp:
it functions propperly and connects when the address starts with tcp://
in the source code there is already a check for this on line 397 of MQTTClient.c but when this check fails the function continues.

@icraggs
Copy link
Contributor

icraggs commented Jun 3, 2024

The connect function (in getaddrinfo) validates the address format, so the idea was not to (imperfectly) duplicate function which already exists in getaddrinfo. The switch on tcp://, ssl://, ws:// is mainly there to select the right protocol to use - an empty string defaults to TCP.

With your erroneous string, the protocol trace looks like this:

Trace : 5, 19700101 010000.000 getaddrinfo failed for addr tcp:test.mosquitto.org with rc 8
Trace : 5, 19700101 010000.000 tcp:test.mosquitto.org is not a valid IP address

One request on the todo list for a while is improved connection errors #937, which although are available in the trace or error callbacks, could be surfaced more readily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants