tech-security archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strscpy



    Date:        Tue, 19 May 2020 19:15:46 +0200
    From:        Maxime Villard <max%m00nbsd.net@localhost>
    Message-ID:  <98432114-2df1-849e-3e2b-d577ba6e9bca%m00nbsd.net@localhost>

  | I see no reason to want to have a string copy function able
  | to copy a terabyte worth of string in the kernel

No, of course not.   My point was that you're touting this function as
being near perfect - and it isn't.    If we're going to replace strlcpy()
in the kernel (which is probably the right thing to do) we should replace
it with something that is designed properly, not just another hack.

  | Also, FYI, there is a difference between source ASM language

which is what I meant .. string functions tend to be important enough
(and simple enough) that writing them in assembler can bring large
gains ... the reference to what the compiler might do was just to ack
that there's no point doing that if the function is one the compiler
knows, and already generates optimised code for.

  | And finally, I can't even begin to count the thousands of problems
  | we would be getting with a 16bit port; never gonna happen on NetBSD.

Again, of course, and again, that was just pointing out that the function
isn't as well designed as it was made out to be.

  | More to the point: the overloading with negative errnos is typical
  | in the linux world, and I understand we may not want to use that
  | convention in NetBSD. I would therefore suggest my earlier version,
  | which was using -1 as error code.

That would be better, but still not as clean as separating the error
and length return values (which in C means returning one of them via
a pointer arg).

Is there really some great difficulty in just using copystr() more ?

If you really have to you could do (in some .h file):

	static inline ssize_t
	strscpy(void *d. const void *s, size_t l) {
		size_t len;
		int r = copystr(s, d, l, &len);
		if (r != 0 || len == 0 || len > SSIZE_MAX)
			return -1;
		return (ssize_t)(len - 1);
	}

or something like that.

kre



Home | Main Index | Thread Index | Old Index