The functions

  shishi_cfg_clientkdcetype_set()

and

  shishi_cfg_authorizationtype_set()

are both throwing segmentation faults every time
they are fed with constant value strings. The reason
is that they both depend on strtok_r() which must
be given writeable strings. Simple calls to xstrdup()
resolve this issue.

As a second matter, both functions always return SHISHI_OK.
This is not reasonable, so a change is implemented that returns
SHISHI_OK whenever at least one valid value was found and set
for the intended configuration entity.

Best regards,

  Mats Erik Andersson
>From 4245dea4c341f5e0aedc9bd487a2f787171bebac Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson <g...@gisladisker.se>
Date: Tue, 7 Aug 2012 21:26:48 +0200
Subject: [PATCH 2/3] Segfault in config list parsing.

---
 lib/cfg.c |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/lib/cfg.c b/lib/cfg.c
index ce06da9..a0e39b3 100644
--- a/lib/cfg.c
+++ b/lib/cfg.c
@@ -584,7 +584,7 @@ shishi_cfg_clientkdcetype_fast (Shishi * handle)
 
 /**
  * shishi_cfg_clientkdcetype_set:
- * @handle: Shishi library handle create by shishi_init().
+ * @handle: Shishi library handle created by shishi_init().
  * @value: string with encryption types.
  *
  * Set the "client-kdc-etypes" configuration option from given string.
@@ -592,20 +592,23 @@ shishi_cfg_clientkdcetype_fast (Shishi * handle)
  * by comma or whitespace, e.g. "aes256-cts-hmac-sha1-96
  * des3-cbc-sha1-kd des-cbc-md5".
  *
- * Return value: Return SHISHI_OK iff successful.
+ * Return value: Returns SHISHI_OK if successful.
  **/
 int
 shishi_cfg_clientkdcetype_set (Shishi * handle, char *value)
 {
   char *ptrptr;
-  char *val;
+  char *val, *tmpvalue;
   int i;
   int tot = 0;
+  int rc = SHISHI_INVALID_ARGUMENT;
 
   if (value == NULL || *value == '\0')
     return SHISHI_OK;
 
-  for (i = 0; (val = strtok_r (i == 0 ? value : NULL, ", \t", &ptrptr)); i++)
+  tmpvalue = xstrdup (value);
+
+  for (i = 0; (val = strtok_r (i == 0 ? tmpvalue : NULL, ", \t", &ptrptr)); i++)
     {
       int etype = shishi_cipher_parse (val);
 
@@ -621,35 +624,41 @@ shishi_cfg_clientkdcetype_set (Shishi * handle, char *value)
 	  handle->clientkdcetypes = new;
 	  handle->clientkdcetypes[tot - 1] = etype;
 	  handle->nclientkdcetypes = tot;
+	  rc = SHISHI_OK;	/* At least one valid type.  */
 	}
     }
 
-  return SHISHI_OK;
+  free (tmpvalue);
+
+  return rc;
 }
 
 /**
  * shishi_cfg_authorizationtype_set:
- * @handle: Shishi library handle create by shishi_init().
+ * @handle: Shishi library handle created by shishi_init().
  * @value: string with authorization types.
  *
  * Set the "authorization-types" configuration option from given string.
  * The string contains authorization types (integer or names) separated
  * by comma or whitespace, e.g. "basic k5login".
  *
- * Return value: Return SHISHI_OK iff successful.
+ * Return value: Returns SHISHI_OK if successful.
  **/
 int
 shishi_cfg_authorizationtype_set (Shishi * handle, char *value)
 {
   char *ptrptr;
-  char *val;
+  char *val, *tmpvalue;
   int i;
   int tot = 0;
+  int rc = SHISHI_INVALID_ARGUMENT;
 
   if (value == NULL || *value == '\0')
     return SHISHI_OK;
 
-  for (i = 0; (val = strtok_r (i == 0 ? value : NULL, ", \t", &ptrptr)); i++)
+  tmpvalue = xstrdup (value);
+
+  for (i = 0; (val = strtok_r (i == 0 ? tmpvalue : NULL, ", \t", &ptrptr)); i++)
     {
       int atype = shishi_authorization_parse (val);
 
@@ -666,8 +675,11 @@ shishi_cfg_authorizationtype_set (Shishi * handle, char *value)
 	  handle->authorizationtypes = new;
 	  handle->authorizationtypes[tot - 1] = atype;
 	  handle->nauthorizationtypes = tot;
+	  rc = SHISHI_OK;	/* At least one valid type.  */
 	}
     }
 
-  return SHISHI_OK;
+  free (tmpvalue);
+
+  return rc;
 }
-- 
1.7.2.5

_______________________________________________
Help-shishi mailing list
Help-shishi@gnu.org
https://lists.gnu.org/mailman/listinfo/help-shishi

Reply via email to