Re: copystr(9) vs strlcpy

2022-12-25 Thread Crystal Kolipe
On Sun, Dec 25, 2022 at 08:07:11PM +, Miod Vallat wrote: > Indeed! So the third copystr() call could be replaced with this: > > Index: sys/kern/vfs_lookup.c > === > RCS file: /OpenBSD/src/sys/kern/vfs_lookup.c,v > retrieving

Re: copystr(9) vs strlcpy

2022-12-25 Thread Miod Vallat
> > In other words, > > copystr(src, dst, dstsiz, len) > > is equivalent to: > > if (strlcpy(dst, src, dstsiz) >= dstsiz) > > return ENAMETOOLONG; > > if (len != NULL) > > *len = strlen(dst); > > This should be *len = strlen(dst)+1 as copystr includes the

Re: copystr(9) vs strlcpy

2022-12-25 Thread Crystal Kolipe
Hi Miod, On Sun, Dec 25, 2022 at 05:21:50PM +, Miod Vallat wrote: > In other words, > copystr(src, dst, dstsiz, len) > is equivalent to: > if (strlcpy(dst, src, dstsiz) >= dstsiz) > return ENAMETOOLONG; > if (len != NULL) > *len = strlen(dst);

Re: copystr(9) vs strlcpy

2022-12-25 Thread Todd C . Miller
On Sun, 25 Dec 2022 17:21:50 +, Miod Vallat wrote: > Now, there are three uses of copystr() left in the kernel, and two of > them ignore the return value of copystr(), and do not need the length of > the result to be returned. > > These two can be trivially replaced with strlcpy() calls.

copystr(9) vs strlcpy

2022-12-25 Thread Miod Vallat
Ho ho ho, copystr(9) is a very old and seldom used kernel function, which performs a bounded string copy and optionally returns the length of the copied string. In other words, copystr(src, dst, dstsiz, len) is equivalent to: if (strlcpy(dst, src, dstsiz) >= dstsiz)