[SSSD] [PATCH] NSS: Fix DEBUG formatting of cmdctx->id

Jakub Hrozek jhrozek at redhat.com
Thu Jan 16 20:24:43 UTC 2014


While looking at another issue I realized that we used a wrong
formatting conversion for UID/GID values - %d. For very large values,
there were sometimes overflows (-1) in the DEBUG logs. The attached
patch converts the format specifier to PRIu32 as the value we print is
uint32_t.

I'm fine with pushing this patch atop Nikolai's patches so that we don't
make him rebase the large patchset again.
-------------- next part --------------
>From 63a2ae12ebc929873c52a59991b5cb8aa4e3db6e Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Thu, 16 Jan 2014 21:10:46 +0100
Subject: [PATCH 1/2] NSS: Fix DEBUG formatting of cmdctx->id

Sometimes a UID/GID value was printed using the %d format specifier
which caused overflows for very large values of ID.
---
 src/responder/nss/nsssrv_cmd.c | 52 +++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index 4dc5bf6d8707e399e380a47ea88e09df78f45412..16209c95fa88c3a67c8cc29ba136107a259cce5b 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -1319,9 +1319,9 @@ static int nss_cmd_getpwuid_search(struct nss_dom_ctx *dctx)
         /* check that the uid is valid for this domain */
         if ((dom->id_min && (cmdctx->id < dom->id_min)) ||
             (dom->id_max && (cmdctx->id > dom->id_max))) {
-            DEBUG(4, ("Uid [%lu] does not exist in domain [%s]! "
+            DEBUG(4, ("Uid [%"PRIu32"] does not exist in domain [%s]! "
                       "(id out of range)\n",
-                      (unsigned long)cmdctx->id, dom->name));
+                      cmdctx->id, dom->name));
             if (cmdctx->check_next) {
                 dom = get_next_domain(dom, true);
                 continue;
@@ -1339,7 +1339,7 @@ static int nss_cmd_getpwuid_search(struct nss_dom_ctx *dctx)
         /* make sure to update the dctx if we changed domain */
         dctx->domain = dom;
 
-        DEBUG(4, ("Requesting info for [%d@%s]\n", cmdctx->id, dom->name));
+        DEBUG(4, ("Requesting info for [%"PRIu32"@%s]\n", cmdctx->id, dom->name));
 
         if (dom->sysdb == NULL) {
             DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
@@ -1389,7 +1389,7 @@ static int nss_cmd_getpwuid_search(struct nss_dom_ctx *dctx)
         }
 
         /* One result found */
-        DEBUG(6, ("Returning info for uid [%d@%s]\n", cmdctx->id, dom->name));
+        DEBUG(6, ("Returning info for uid [%"PRIu32"@%s]\n", cmdctx->id, dom->name));
 
         ret = EOK;
         goto done;
@@ -1403,11 +1403,11 @@ done:
         err = sss_ncache_set_uid(nctx->ncache, false, cmdctx->id);
         if (err != EOK) {
             DEBUG(SSSDBG_MINOR_FAILURE,
-                ("Cannot set negative cache for UID %d\n", cmdctx->id));
+                ("Cannot set negative cache for UID %"PRIu32"\n", cmdctx->id));
         }
     }
 
-    DEBUG(SSSDBG_MINOR_FAILURE, ("No matching domain found for [%d]\n", cmdctx->id));
+    DEBUG(SSSDBG_MINOR_FAILURE, ("No matching domain found for [%"PRIu32"]\n", cmdctx->id));
     return ret;
 }
 
@@ -1464,7 +1464,7 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
     }
     cmdctx->id = *((uint32_t *)body);
 
-    DEBUG(SSSDBG_TRACE_FUNC, ("Running command [%d] with id [%d].\n",
+    DEBUG(SSSDBG_TRACE_FUNC, ("Running command [%d] with id [%"PRIu32"].\n",
                               dctx->cmdctx->cmd, cmdctx->id));
 
     switch(dctx->cmdctx->cmd) {
@@ -1472,8 +1472,8 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
         ret = sss_ncache_check_uid(nctx->ncache, nctx->neg_timeout, cmdctx->id);
         if (ret == EEXIST) {
             DEBUG(SSSDBG_TRACE_FUNC,
-                  ("Uid [%lu] does not exist! (negative cache)\n",
-                   (unsigned long)cmdctx->id));
+                  ("Uid [%"PRIu32"] does not exist! (negative cache)\n",
+                   cmdctx->id));
             ret = ENOENT;
             goto done;
         }
@@ -1482,8 +1482,8 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
         ret = sss_ncache_check_gid(nctx->ncache, nctx->neg_timeout, cmdctx->id);
         if (ret == EEXIST) {
             DEBUG(SSSDBG_TRACE_FUNC,
-                  ("Gid [%lu] does not exist! (negative cache)\n",
-                   (unsigned long)cmdctx->id));
+                  ("Gid [%"PRIu32"] does not exist! (negative cache)\n",
+                   cmdctx->id));
             ret = ENOENT;
             goto done;
         }
@@ -1496,8 +1496,8 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
         }
         if (ret == EEXIST) {
             DEBUG(SSSDBG_TRACE_FUNC,
-                  ("Id [%lu] does not exist! (negative cache)\n",
-                   (unsigned long)cmdctx->id));
+                  ("Id [%"PRIu32"] does not exist! (negative cache)\n",
+                   cmdctx->id));
             ret = ENOENT;
             goto done;
         }
@@ -2791,9 +2791,9 @@ static int nss_cmd_getgrgid_search(struct nss_dom_ctx *dctx)
         /* check that the gid is valid for this domain */
         if ((dom->id_min && (cmdctx->id < dom->id_min)) ||
             (dom->id_max && (cmdctx->id > dom->id_max))) {
-            DEBUG(4, ("Gid [%lu] does not exist in domain [%s]! "
+            DEBUG(4, ("Gid [%"PRIu32"] does not exist in domain [%s]! "
                       "(id out of range)\n",
-                      (unsigned long)cmdctx->id, dom->name));
+                      cmdctx->id, dom->name));
             if (cmdctx->check_next) {
                 dom = get_next_domain(dom, true);
                 continue;
@@ -2811,7 +2811,7 @@ static int nss_cmd_getgrgid_search(struct nss_dom_ctx *dctx)
         /* make sure to update the dctx if we changed domain */
         dctx->domain = dom;
 
-        DEBUG(4, ("Requesting info for [%d@%s]\n", cmdctx->id, dom->name));
+        DEBUG(4, ("Requesting info for [%"PRIu32"@%s]\n", cmdctx->id, dom->name));
 
         if (dom->sysdb == NULL) {
             DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
@@ -2861,7 +2861,7 @@ static int nss_cmd_getgrgid_search(struct nss_dom_ctx *dctx)
         }
 
         /* One result found */
-        DEBUG(6, ("Returning info for gid [%d@%s]\n", cmdctx->id, dom->name));
+        DEBUG(6, ("Returning info for gid [%"PRIu32"@%s]\n", cmdctx->id, dom->name));
 
         /* Success. Break from the loop and return EOK */
         ret = EOK;
@@ -2876,11 +2876,11 @@ done:
         err = sss_ncache_set_gid(nctx->ncache, false, cmdctx->id);
         if (err != EOK) {
             DEBUG(SSSDBG_MINOR_FAILURE,
-                ("Cannot set negative cache for GID %d\n", cmdctx->id));
+                ("Cannot set negative cache for GID %"PRIu32"\n", cmdctx->id));
         }
     }
 
-    DEBUG(SSSDBG_MINOR_FAILURE, ("No matching domain found for [%d]\n", cmdctx->id));
+    DEBUG(SSSDBG_MINOR_FAILURE, ("No matching domain found for [%"PRIu32"]\n", cmdctx->id));
     return ret;
 }
 
@@ -3783,9 +3783,9 @@ static errno_t nss_cmd_getsidby_search(struct nss_dom_ctx *dctx)
             if ((dom->id_min && (cmdctx->id < dom->id_min)) ||
                 (dom->id_max && (cmdctx->id > dom->id_max))) {
                 DEBUG(SSSDBG_TRACE_FUNC,
-                      ("Uid [%lu] does not exist in domain [%s]! "
+                      ("Uid [%"PRIu32"] does not exist in domain [%s]! "
                        "(id out of range)\n",
-                       (unsigned long)cmdctx->id, dom->name));
+                       cmdctx->id, dom->name));
                 if (cmdctx->check_next) {
                     dom = get_next_domain(dom, true);
                     continue;
@@ -3813,7 +3813,7 @@ static errno_t nss_cmd_getsidby_search(struct nss_dom_ctx *dctx)
         dctx->domain = dom;
 
         if (cmdctx->cmd == SSS_NSS_GETSIDBYID) {
-            DEBUG(SSSDBG_TRACE_FUNC, ("Requesting info for [%d@%s]\n",
+            DEBUG(SSSDBG_TRACE_FUNC, ("Requesting info for [%"PRIu32"@%s]\n",
                                       cmdctx->id, dom->name));
         } else {
             talloc_free(name);
@@ -4006,7 +4006,7 @@ static errno_t nss_cmd_getsidby_search(struct nss_dom_ctx *dctx)
 
         /* One result found */
         if (cmdctx->cmd == SSS_NSS_GETSIDBYID) {
-            DEBUG(SSSDBG_TRACE_FUNC, ("Returning info for id [%d@%s]\n",
+            DEBUG(SSSDBG_TRACE_FUNC, ("Returning info for id [%"PRIu32"@%s]\n",
                                      cmdctx->id, dom->name));
         } else {
             DEBUG(SSSDBG_TRACE_FUNC, ("Returning info for user/group [%s@%s]\n",
@@ -4025,17 +4025,17 @@ done:
         /* The entry was not found, need to set result in negative cache */
         if (cmdctx->cmd == SSS_NSS_GETSIDBYID) {
             DEBUG(SSSDBG_MINOR_FAILURE,
-                ("No matching domain found for [%d], fail!\n", cmdctx->id));
+                ("No matching domain found for [%"PRIu32"], fail!\n", cmdctx->id));
             err = sss_ncache_set_uid(nctx->ncache, false, cmdctx->id);
             if (err != EOK) {
                 DEBUG(SSSDBG_MINOR_FAILURE,
-                    ("Cannot set negative cache for UID %d\n", cmdctx->id));
+                    ("Cannot set negative cache for UID %"PRIu32"\n", cmdctx->id));
             }
 
             err = sss_ncache_set_gid(nctx->ncache, false, cmdctx->id);
             if (err != EOK) {
                 DEBUG(SSSDBG_MINOR_FAILURE,
-                    ("Cannot set negative cache for GID %d\n", cmdctx->id));
+                    ("Cannot set negative cache for GID %"PRIu32"\n", cmdctx->id));
             }
         } else {
             DEBUG(SSSDBG_MINOR_FAILURE,
-- 
1.8.4.2



More information about the sssd-devel mailing list