[SSSD] handling NULL params in sss_parse_name
Lukas Slebodnik
lslebodn at redhat.com
Mon Jan 27 12:02:19 UTC 2014
On (26/01/14 13:02), Pavel Reichl wrote:
>Hello,
>
>sss_parse_name currently SIGSEGVs if any of output parameters (domain,
>name) is a NULL. I think it may be useful to support passing NULL
>arguments as not always both pieces of information are needed.
>
>Please see attached patch.
>
>PR
>From 1cbd8b48b1359bbba8315cd904b93643594dd0d3 Mon Sep 17 00:00:00 2001
>From: Pavel Reichl <preichl at redhat.com>
>Date: Sun, 26 Jan 2014 12:39:43 +0000
>Subject: [PATCH] utils: handling NULL params in sss_parse_name
>
>---
> src/util/usertools.c | 48 ++++++++++++++++++++++++++----------------------
> 1 file changed, 26 insertions(+), 22 deletions(-)
>
>diff --git a/src/util/usertools.c b/src/util/usertools.c
>index c77aa7ce097d32d002bf7168bea91082b0e8e4dd..24665d21f0718f35c4844a359a324eba8b8ff8da 100644
>--- a/src/util/usertools.c
>+++ b/src/util/usertools.c
>@@ -327,31 +327,35 @@ int sss_parse_name(TALLOC_CTX *memctx,
>
> strnum = ret;
>
>- result = NULL;
>- ret = pcre_get_named_substring(re, orig, ovec, strnum, "name", &result);
>- if (ret < 0 || !result) {
>- DEBUG(2, ("Name not found!\n"));
>- return EINVAL;
>+ if (name != NULL) {
>+ result = NULL;
>+ ret = pcre_get_named_substring(re, orig, ovec, strnum, "name", &result);
>+ if (ret < 0 || !result) {
>+ DEBUG(2, ("Name not found!\n"));
>+ return EINVAL;
>+ }
>+ *name = talloc_strdup(memctx, result);
>+ pcre_free_substring(result);
>+ if (!*name) return ENOMEM;
> }
>- *name = talloc_strdup(memctx, result);
>- pcre_free_substring(result);
>- if (!*name) return ENOMEM;
>
>-
>- result = NULL;
>- ret = pcre_get_named_substring(re, orig, ovec, strnum, "domain", &result);
>- if (ret < 0 || !result) {
>- DEBUG(4, ("Domain not provided!\n"));
>- *domain = NULL;
>- } else {
>- /* ignore "" string */
>- if (*result) {
>- *domain = talloc_strdup(memctx, result);
>- pcre_free_substring(result);
>- if (!*domain) return ENOMEM;
>- } else {
>- pcre_free_substring(result);
>+ if (domain != NULL) {
>+ result = NULL;
>+ ret = pcre_get_named_substring(re, orig, ovec, strnum, "domain",
>+ &result);
>+ if (ret < 0 || !result) {
>+ DEBUG(4, ("Domain not provided!\n"));
> *domain = NULL;
>+ } else {
>+ /* ignore "" string */
>+ if (*result) {
>+ *domain = talloc_strdup(memctx, result);
>+ pcre_free_substring(result);
>+ if (!*domain) return ENOMEM;
>+ } else {
>+ pcre_free_substring(result);
>+ *domain = NULL;
>+ }
> }
> }
>
>--
>1.8.4.2
>
Can you also add '_' as prefix for output parameters into declaration.
We are not consistent in this and I cannot find this in coding style,
but it improves readability.
LS
More information about the sssd-devel
mailing list