JTEncode icon indicating copy to clipboard operation
JTEncode copied to clipboard

JTEncode.cpp can cause unterminated character array, leading to undefined behavior

Open EngineerGuy314 opened this issue 1 year ago • 0 comments

this is regarding lines 677 to 687 in the wspr_message_prep function in JTEncode.cpp.

The code cycle through 12 characters of "call", and unless a char is '/', '<' or '>' it replaces non digits or non uppercase characters with a space.

The problem is if "call" points to a 6 character callsign that is null terminated in the 7th character, then the code replaces the null with a space. You now have an unterminated character array with undefined garbage in characters 8 through 12.

Not an issue 99% of the time, because the garbage characters will probably also be replaced by spaces.

But every once in a while the garbage characters include a '/' which will not get replaced with a space. The downstream code sees the '/' and thinks your trying to send a WSPR Type-3 message with prefix, and you end up with an incorrectly encoded WSPR message.

A workaround is to make sure any string you pass for the call is padded with spaces to the 12th character. A better solution imho is if the code in lines 677 to 687 would leave NULLs alone.

EngineerGuy314 avatar Feb 10 '25 14:02 EngineerGuy314