[SSSD] [PATCH] fill_id() fix LE/BE issue with wrong data type

Sumit Bose sbose at redhat.com
Thu Jan 29 20:17:28 UTC 2015


Hi,

we try to squeeze a 64bit type into a 32bit one which kind of works on
little-endian because we checked that the value is not larger then
UINT32_MAX before but fails on big-endian. This patch tries to fix it.

bye,
Sumit
-------------- next part --------------
From d3673d7f904ee0642df8dd2e2a2206b9d19fc5fa Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Thu, 29 Jan 2015 20:31:19 +0100
Subject: [PATCH] fill_id() fix LE/BE issue with wrong data type

Related to https://fedorahosted.org/sssd/ticket/1588
---
 src/responder/nss/nsssrv_cmd.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index 93b220cc8cad4c7cdb0c5daab7c4b2f0748f1f9d..1affde874d8b8e8798b3d195090139ba5a433ace 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -4867,18 +4867,20 @@ static errno_t fill_id(struct sss_packet *packet,
     uint8_t *body;
     size_t blen;
     size_t pctr = 0;
-    uint64_t id;
+    uint64_t tmp_id;
+    uint32_t id;
 
     if (id_type == SSS_ID_TYPE_GID) {
-        id = ldb_msg_find_attr_as_uint64(msg, SYSDB_GIDNUM, 0);
+        tmp_id = ldb_msg_find_attr_as_uint64(msg, SYSDB_GIDNUM, 0);
     } else {
-        id = ldb_msg_find_attr_as_uint64(msg, SYSDB_UIDNUM, 0);
+        tmp_id = ldb_msg_find_attr_as_uint64(msg, SYSDB_UIDNUM, 0);
     }
 
-    if (id == 0 || id >= UINT32_MAX) {
+    if (tmp_id == 0 || tmp_id >= UINT32_MAX) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Invalid POSIX ID.\n");
         return EINVAL;
     }
+    id = (uint32_t) tmp_id;
 
     ret = sss_packet_grow(packet, 4 * sizeof(uint32_t));
     if (ret != EOK) {
-- 
2.1.0



More information about the sssd-devel mailing list