TLeconte / vdlm2dec

vdl mode 2 SDR decoder
GNU General Public License v2.0
75 stars 23 forks source link

Truncated hostname results unterminated string as station id #33

Closed tfdhu closed 6 years ago

tfdhu commented 6 years ago

My Raspberry Pi box has 8 character hostname 'acarspi3', that does not fit in the given buffer with the terminating null character. In principle hostname() function should care of that, but the glibc implementation has an undefined behaviour in this case and omits the terminator, resulting garbage as station id in JSON output. The following modification solved the issue:

char sys_hostname[9]; sys_hostname[sizeof(sys_hostname) - 1] = '\0'; gethostname(sys_hostname, sizeof(sys_hostname) - 1);

TLeconte commented 6 years ago

fixed