From: Dario Faggioli <dario.faggioli@citrix.com>
To: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com,
ian.campbell@citrix.com, wei.liu2@citrix.com
Cc: xen-devel@lists.xen.org
Subject: Re: [PATCH] libxl: Be more careful with error handling in libxl__dm_runas_helper()
Date: Thu, 26 Nov 2015 10:15:12 +0100 [thread overview]
Message-ID: <1448529312.7833.208.camel@citrix.com> (raw)
In-Reply-To: <1448488569-3003-1-git-send-email-boris.ostrovsky@oracle.com>
[-- Attachment #1.1: Type: text/plain, Size: 2670 bytes --]
On Wed, 2015-11-25 at 16:56 -0500, Boris Ostrovsky wrote:
> getpwnam_r() has fairly complicated return rules. From man pages:
>
> RETURN VALUE
> ...
> On success, getpwnam_r() and getpwuid_r() return zero, and set
> *result to pwd. If no matching password record was found,
> these
> functions return 0 and store NULL in *result. In case of error,
> an error number is returned, and NULL is stored in *result.
> ERRORS
> 0 or ENOENT or ESRCH or EBADF or EPERM or ...
> The given name or uid was not found.
>
Wow! Given how much he likes error handling, I can't wait to see Ian
Jackson jumping on this! :-PP
> While it's not clear what ellipses are meant to be, the way we
> currently
> treat return values from getpwnam_r() is no sufficient. In fact, two
> of
> my systems behave differently when username is not found: one returns
> ENOENT and the other returns 0. Both set *result to NULL.
>
Nice. Or not. :-/
Anyway, given exactly those ellipses, wouldn't it be safer to go the
other way round? I mean something like:
> @@ -740,12 +740,17 @@ static int libxl__dm_runas_helper(libxl__gc
> *gc, const char *username)
> ret = getpwnam_r(username, &pwd, buf, buf_size, &user);
> if (ret == ERANGE) {
> buf_size += 128;
> + if (retry_cnt++ > 10)
> + return ERROR_FAIL;
> continue;
> }
> - if (ret != 0)
> - return ERROR_FAIL;
> - if (user != NULL)
> - return 1;
> + if (user == NULL) {
> + if (!ret || (ret == ENOENT) || (ret == ESRCH) ||
> + (ret == EBADF) || (ret == EPERM))
> + return ERROR_NOTFOUND;
> + else
> + return ERROR_FAIL;
> + }
>
if (user == NULL) {
if (ret == EINTR || ret == EIO || ret == EMFILE ||
ret == ENFILE || ret == ENOMEM)
return ERROR_FAIL;
else
return ERROR_NOTFOUND;
}
Also, considering libxl attitude toward out-of-memory errors, should we
deal with ENOMEM in a special way?
Regards,
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2015-11-26 9:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-25 21:56 [PATCH] libxl: Be more careful with error handling in libxl__dm_runas_helper() Boris Ostrovsky
2015-11-26 9:15 ` Dario Faggioli [this message]
2015-11-26 10:03 ` Ian Campbell
2015-11-26 10:16 ` Ian Campbell
2015-11-26 17:47 ` Ian Jackson
2015-11-27 9:29 ` Ian Campbell
2015-11-26 10:26 ` Wei Liu
2015-11-26 17:45 ` Ian Jackson
2015-11-27 9:40 ` Ian Campbell
2015-11-30 18:24 ` Boris Ostrovsky
2015-12-01 14:38 ` Ian Campbell
2015-12-01 15:32 ` Boris Ostrovsky
2015-12-01 15:52 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448529312.7833.208.camel@citrix.com \
--to=dario.faggioli@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.