If it returns 50 then the creds structure is not valid, and can't be copied
from.  It only returns valid creds *IF* success is indicated by 0.  But then
you convert 50 to a return value of 0, and hide any indication that things
went weird?

No way, I'm not buying your argument.   I think the code is making the
correct choice now.

Martin Vahlensieck <[email protected]> wrote:

> Hi there
> 
> From the getsockopt(2) manual page says getsockopt(2) returns -1 on
> error and 0 on success. Also getpeereid(3) only lists those 2 values.
> This diff makes the return value check in getpeereid explicit. I guess
> this is how it is done elsewhere in the tree (there is a commit turning
> a bunch of "... < 0" to "== -1" I think this falls under that category).
> 
> Best,
> 
> Martin
> 
> Index: net/getpeereid.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/net/getpeereid.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 getpeereid.c
> --- net/getpeereid.c  1 Jul 2010 19:15:30 -0000       1.1
> +++ net/getpeereid.c  26 Apr 2020 20:28:50 -0000
> @@ -28,7 +28,7 @@ getpeereid(int s, uid_t *euid, gid_t *eg
>  
>       error = getsockopt(s, SOL_SOCKET, SO_PEERCRED,
>           &creds, &credslen);
> -     if (error)
> +     if (error == -1)
>               return (error);
>       *euid = creds.uid;
>       *egid = creds.gid;
> 

Reply via email to