TLeconte / vdlm2dec

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

Truncated hostname results unterminated string as station id #33

Closed tfdhu closed 5 years ago

tfdhu commented 5 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 5 years ago

fixed