[SSSD] [PATCH] Fix off-by-one error in principal selection

Jakub Hrozek jhrozek at redhat.com
Thu Mar 29 19:00:17 UTC 2012


On Thu, Mar 29, 2012 at 02:27:36PM -0400, Stephen Gallagher wrote:
> On Tue, 2012-03-27 at 15:27 -0400, Jakub Hrozek wrote:
> > Just a one-liner but was not exactly easy to find..
> > 
> > https://fedorahosted.org/sssd/ticket/1269
> 
> Nack.
> 
> On close inspection, it looks like we're not properly truncating the
> 'primary_str' variable after this. We're setting the NULL-terminator to
> be after the asterisk, which is pretty much guaranteed to fail the
> strncmp() on line 426.

The strncmp worked because we were only comparing tmp_len-1 bytes and
never got to the asterisk. But it's confusing, I fixed the NULL
terminator.
-------------- next part --------------
From 9bb554cc2efe8d237e0e4fe8b8d25dd807829814 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Tue, 27 Mar 2012 15:23:23 -0400
Subject: [PATCH] Fix off-by-one error in principal selection

https://fedorahosted.org/sssd/ticket/1269
---
 src/util/sss_krb5.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/util/sss_krb5.c b/src/util/sss_krb5.c
index 75ce2a59a89da716060223c8302cba6426cd6350..73bd5b8e945a7b34f076338fe938ae1e03cc566d 100644
--- a/src/util/sss_krb5.c
+++ b/src/util/sss_krb5.c
@@ -390,7 +390,7 @@ static bool match_principal(krb5_context ctx,
     const char *realm_name;
     int realm_len;
 
-    int mode = MODE_NORMAL;
+    enum matching_mode mode = MODE_NORMAL;
     TALLOC_CTX *tmp_ctx;
     bool ret = false;
 
@@ -404,10 +404,10 @@ static bool match_principal(krb5_context ctx,
 
     if (pattern_primary) {
         tmp_len = strlen(pattern_primary);
-        if (pattern_primary[tmp_len] == '*') {
+        if (pattern_primary[tmp_len-1] == '*') {
             mode = MODE_PREFIX;
             primary_str = talloc_strdup(tmp_ctx, pattern_primary);
-            primary_str[tmp_len] = '\0';
+            primary_str[tmp_len-1] = '\0';
             primary_str_len = tmp_len-1;
         } else if (pattern_primary[0] == '*') {
             mode = MODE_POSTFIX;
-- 
1.7.7.6



More information about the sssd-devel mailing list