Skip to content

mosquitto_topic_matches_sub2 doesn't work; ignores lengths #2364

Closed
@snej

Description

@snej

mosquitto_topic_matches_sub2 is an alternate version of mosquitto_topic_matches_sub that doesn't require C strings, instead taking both strings as pointer/length pairs. (I appreciate this, since my code does not use null-terminated strings!)

Unfortunately it does not behave that way. Instead, it ignores the sublen and topiclen parameters and uses NUL bytes to find the ends of the strings. (In fact it and mosquitto_topic_matches_sub share the same implementation code -- the latter is just a stub that calls it with 0 for the length parameters.)

The effect is that, if you pass it strings that don't end in a NUL byte, it will run off the ends of the strings and typically either produce incorrect results, or perhaps crash if it falls off the end of mapped memory. In my case it promptly triggered a visit from the Clang address sanitizer the first time I tried calling it.

Workaround is to copy both strings into heap buffers, zero-terminate them, call mosquitto_topic_matches_sub, and free the buffers.

I'm using commit 9afeeb1, from Sept 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions