* NSS modules and errno if key not found
@ 2004-03-27 17:53 Thorsten Kukuk
2004-03-29 20:16 ` Thorsten Kukuk
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Kukuk @ 2004-03-27 17:53 UTC (permalink / raw)
To: libc-hacker
Hi,
I found a problem today when debugging some NSS releated problems.
If somebody calls getgrnam_r (or any other reentrant NSS function),
the return value of the function will be errno if the status is not
NSS_STATUS_SUCCESS.
But in the case of NSS_STATUS_NOTFOUND, no NSS module sets errno,
so the return value is a random value, but should be zero.
Who should set errno in this case? Should all NSS modules set
errno? Or should we explicit return 0 in the getXXbyYY_r functions
for NSS_STATUS_NOTFOUND?
Testcase:
#include <grp.h>
#include <errno.h>
int main ()
{
char buffer[8048];
struct group *result = (void *)12, gbuf;
errno = 211;
int ret = getgrnam_r ("notexistent", &gbuf, buffer, sizeof (buffer),
&result);
printf ("errno=%d, ret=%d, result=%p\n", errno, ret, result);
return 0;
}
--
Thorsten Kukuk http://www.suse.de/~kukuk/ kukuk@suse.de
SuSE Linux AG Maxfeldstr. 5 D-90409 Nuernberg
--------------------------------------------------------------------
Key fingerprint = A368 676B 5E1B 3E46 CFCE 2D97 F8FD 4E23 56C6 FB4B
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: NSS modules and errno if key not found
2004-03-27 17:53 NSS modules and errno if key not found Thorsten Kukuk
@ 2004-03-29 20:16 ` Thorsten Kukuk
2004-03-30 0:01 ` Ulrich Drepper
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Kukuk @ 2004-03-29 20:16 UTC (permalink / raw)
To: libc-hacker
On Fri, Mar 26, Thorsten Kukuk wrote:
>
> Hi,
>
> I found a problem today when debugging some NSS releated problems.
>
> If somebody calls getgrnam_r (or any other reentrant NSS function),
> the return value of the function will be errno if the status is not
> NSS_STATUS_SUCCESS.
>
> But in the case of NSS_STATUS_NOTFOUND, no NSS module sets errno,
> so the return value is a random value, but should be zero.
>
> Who should set errno in this case? Should all NSS modules set
> errno? Or should we explicit return 0 in the getXXbyYY_r functions
> for NSS_STATUS_NOTFOUND?
Looking at getXXbyYY_r.c, we can only change it in this file.
My proposed fix:
2004-03-27 Thorsten Kukuk <kukuk@suse.de>
* nss/getXXbyYY_r.c: If key is not found, return zero, not
a random errno value.
--- nss/getXXbyYY_r.c 10 Mar 2004 09:28:25 -0000 1.57
+++ nss/getXXbyYY_r.c 27 Mar 2004 08:44:52 -0000
@@ -256,6 +256,11 @@
else if (status == NSS_STATUS_TRYAGAIN && *h_errnop != NETDB_INTERNAL)
res = EAGAIN;
#endif
+ else if (status == NSS_STATUS_NOTFOUND)
+ {
+ __set_errno (ENOENT);
+ return 0;
+ }
else
return errno;
--
Thorsten Kukuk http://www.suse.de/~kukuk/ kukuk@suse.de
SuSE Linux AG Maxfeldstr. 5 D-90409 Nuernberg
--------------------------------------------------------------------
Key fingerprint = A368 676B 5E1B 3E46 CFCE 2D97 F8FD 4E23 56C6 FB4B
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: NSS modules and errno if key not found
2004-03-29 20:16 ` Thorsten Kukuk
@ 2004-03-30 0:01 ` Ulrich Drepper
0 siblings, 0 replies; 3+ messages in thread
From: Ulrich Drepper @ 2004-03-30 0:01 UTC (permalink / raw)
To: Thorsten Kukuk; +Cc: libc-hacker
Thorsten Kukuk wrote:
> * nss/getXXbyYY_r.c: If key is not found, return zero, not
> a random errno value.
>
> --- nss/getXXbyYY_r.c 10 Mar 2004 09:28:25 -0000 1.57
> +++ nss/getXXbyYY_r.c 27 Mar 2004 08:44:52 -0000
> @@ -256,6 +256,11 @@
> else if (status == NSS_STATUS_TRYAGAIN && *h_errnop != NETDB_INTERNAL)
> res = EAGAIN;
> #endif
> + else if (status == NSS_STATUS_NOTFOUND)
> + {
> + __set_errno (ENOENT);
> + return 0;
> + }
That's not really necessary, errno need not be set. But since we always
do it for some compatibility reason it is OK. But your patch is not
optimal, take a look at the change I've checked in.
--
⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-03-29 20:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-27 17:53 NSS modules and errno if key not found Thorsten Kukuk
2004-03-29 20:16 ` Thorsten Kukuk
2004-03-30 0:01 ` Ulrich Drepper
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).