[PATCH app/sessreg] Replace strncpy calls with a sane version that always terminates
Alan Coopersmith
alan.coopersmith at oracle.com
Wed Sep 12 23:10:00 UTC 2018
On 09/12/18 12:09 AM, Walter Harms wrote:
>
>
>> Peter Hutterer <peter.hutterer at who-t.net> hat am 12. September 2018 um 06:50
>> geschrieben:
>>
>>
>> Fixes coverity complaints about potentially unterminated strings
>>
>> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
>> ---
>> sessreg.c | 26 +++++++++++++++++---------
>> 1 file changed, 17 insertions(+), 9 deletions(-)
>>
>> diff --git a/sessreg.c b/sessreg.c
>> index 0a8fdb2..53b30b0 100644
>> --- a/sessreg.c
>> +++ b/sessreg.c
>> @@ -192,6 +192,14 @@ sysnerr (int x, const char *s)
>> return x;
>> }
>>
>> +static void
>> +safe_strncpy(char *dest, const char *src, size_t n)
>> +{
>
> if you add
> if (!src)
> return;
>
> you can also remove the if (x) before strncpy()
You'd only be able to remove if's from a couple calls so it doesn't seem
like it really buys you much.
I'd be tempted to handle this for non-glibc platforms with something like
#ifdef HAVE_STRLCPY
#define safe_strncpy strlcpy
#else
static void
safe_strncpy(char *dest, const char *src, size_t n)
{
...
}
#endif
which was going to be another argument against it, but I suppose that
could also just be handled via
#define safe_strncpy(d, s, n) do { \
if (s) { strlcpy(d, s, n); } \
while(0)
--
-Alan Coopersmith- alan.coopersmith at oracle.com
Oracle Solaris Engineering - https://blogs.oracle.com/alanc
More information about the xorg-devel
mailing list