This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 3/5] linux ttyname and ttyname_r: Add tests [BZ #22145]
On Okt 12 2017, Christian Brauner <christian.brauner@mailbox.org> wrote:
>> +static struct result_r
>> +run_ttyname_r (int fd)
>> +{
>> + static char buf[TTY_NAME_MAX];
>> +
>> + struct result_r ret;
>> + errno = 0;
>> + ret.ret = ttyname_r (fd, buf, TTY_NAME_MAX);
>> + ret.err = errno;
>> + if (ret.ret == 0)
>> + ret.name = buf;
>> + else
>> + ret.name = NULL;
>> + return ret;
>> +}
>
> Same problem as before, you're returning stack memory and fail to strdup() the
> result of ttyname{_r}().
In which way? buf is static, and ret is copied to the caller.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."