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

Config file values are truncated after first space. #2059

Closed
jdwhite opened this issue Jan 30, 2021 · 2 comments
Closed

Config file values are truncated after first space. #2059

jdwhite opened this issue Jan 30, 2021 · 2 comments
Milestone

Comments

@jdwhite
Copy link

jdwhite commented Jan 30, 2021

This issue is present in 1.6.12 and 2.0.6.

In the OPTIONS section of the man pages for mosquitto_{pub,sub}, the first sentence reads:

The options below may be given on the command line, but may also be placed in a config file located at $XDG_CONFIG_HOME/[mosquitto_pub/sub] or $HOME/.config/[mosquitto_pub/sub] with one pair of -option value per line.

When parsing mosquitto_{pub,sub}, the values are truncated at the first space instead of end of line. Example:

~/.config/mosquitto_sub:

-h somehost
-p someport
-F %I [%t]: "%p" (retain=%r qos=%q msgid=%m)

yields:

$ mosquitto_sub -t \#
2021-01-29T22:55:31-0600

I've tried escaping the spaces and putting the entire value in single quotes, but escaping spaces isn't valid and wrapping in single quotes yields:

'2021-01-29T22:55:31-0600

~/.config/mosquitto_pub

-h somehost
-p someport 
-f /home/bob/test dir/msg.txt

Will generate an error because the value is truncated:

$ mosquitto_pub -t sometopic
Error: Unable to open file "/home/bob/test".
Error loading input file "/home/bob/test".

As a workaround I've replaced all spaces with underscores, which is awful.

@sectokia
Copy link

sectokia commented Feb 1, 2021

The culprit is in client_shared.c:
args[2] = strtok(NULL, " ");

my suggested bad fix would be:
args[2] = (strlen(line)>strlen(args[1])) ? &line[strlen(args[1])+2] : NULL;

@ralight ralight added this to the 2.0.7 milestone Feb 3, 2021
@ralight
Copy link
Contributor

ralight commented Feb 3, 2021

@sectokia It's much easier than that, just a swap of a " " to "" :)

ralight added a commit that referenced this issue Feb 3, 2021
@ralight ralight closed this as completed in 6c2dca5 Feb 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants