[SSSD] [PATCH] Use uint32_t to copy the service port

Jakub Hrozek jhrozek at redhat.com
Fri May 25 12:22:32 UTC 2012


On Fri, May 25, 2012 at 08:12:56AM -0400, Stephen Gallagher wrote:
> On Fri, 2012-05-25 at 08:09 -0400, Stephen Gallagher wrote:
> > On Fri, 2012-05-25 at 13:56 +0200, Jakub Hrozek wrote:
> > > On Fri, May 25, 2012 at 07:28:06AM -0400, Stephen Gallagher wrote:
> > > > On Fri, 2012-05-25 at 12:46 +0200, Jakub Hrozek wrote:
> > > > > The sss_client was copying 32bit port value, but the NSS responder was
> > > > > reading 16bit port value. This was breaking on Big-Endian machines where
> > > > > we read "the other 16bits".
> > > > > 
> > > > > By the way, is there a reason to use 32bits in the client in the first
> > > > > place? IIRC a port number is a 16 bit value..
> > > > 
> > > > No, you're right. The client should only be sending a 16-bit value.
> > > > 
> > > > Nack.
> > > > Please change the client to send a uint16_t instead.
> > > 
> > > Attached.
> > 
> > 
> > Nack (minor).
> > 
> > Would you mind using SAFEALIGN_SET_UINT16() for the padding? The macro
> > expands to exactly the same code you have there.
> > 

Sure, new patch is attached.

> > Has this been tested on a little-endian and big-endian system?
> 
> Replying to myself, I can confirm that this is working on x86_64 at
> least.

Yes, I also tested on s390x running RHEL6.
-------------- next part --------------
>From 67f45ccd456cebcf3f036508dce1028bc9d5735a Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Fri, 25 May 2012 13:52:32 +0200
Subject: [PATCH] Send 16bit protocol numbers from the sss_client

https://fedorahosted.org/sssd/ticket/1348
---
 src/responder/nss/nsssrv_services.c |    2 +-
 src/sss_client/nss_services.c       |   13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/responder/nss/nsssrv_services.c b/src/responder/nss/nsssrv_services.c
index 2e539f13576d18c97d8c3bff2ced2fd5ed01290f..db8a2ca132b4f47c4d6cd78ce99280486e22f2a0 100644
--- a/src/responder/nss/nsssrv_services.c
+++ b/src/responder/nss/nsssrv_services.c
@@ -1050,7 +1050,7 @@ errno_t parse_getservbyport(TALLOC_CTX *mem_ctx,
     SAFEALIGN_COPY_UINT16(&c, body, NULL);
     port = ntohs(c);
 
-    port_and_padding_len = 2 * sizeof(uint16_t) + sizeof(uint32_t);
+    port_and_padding_len = 2 * sizeof(uint16_t);
     i = port_and_padding_len;
     j = 0;
 
diff --git a/src/sss_client/nss_services.c b/src/sss_client/nss_services.c
index 3f042b4a2a62dbf56b5295e84af8d0371708453a..8f25781a1ec188931157368a2e38067be23c0c00 100644
--- a/src/sss_client/nss_services.c
+++ b/src/sss_client/nss_services.c
@@ -270,6 +270,7 @@ _nss_sss_getservbyport_r(int port, const char *protocol,
     size_t proto_len = 0;
     uint8_t *repbuf;
     uint8_t *data;
+    size_t p = 0;
     size_t replen, len;
     enum nss_status nret;
     int ret;
@@ -285,23 +286,23 @@ _nss_sss_getservbyport_r(int port, const char *protocol,
         }
     }
 
-    rd.len = sizeof(uint32_t)*2 + proto_len + 1;
-    data = malloc(sizeof(char)*rd.len);
+    rd.len = sizeof(uint16_t)*2 + proto_len + 1;
+    data = malloc(sizeof(uint8_t)*rd.len);
     if (data == NULL) {
         nret = NSS_STATUS_TRYAGAIN;
         goto out;
     }
 
-    SAFEALIGN_SET_UINT32(data, port, NULL);
+    SAFEALIGN_SET_UINT16(data, port, &p);
 
     /* Padding */
-    memset(data + sizeof(uint32_t), 0, 4);
+    SAFEALIGN_SET_UINT16(data + p, 0, &p);
 
     if (protocol) {
-        memcpy(data + sizeof(uint32_t)*2, protocol, proto_len + 1);
+        memcpy(data + p, protocol, proto_len + 1);
     } else {
         /* No protocol specified, pass empty string */
-        data[sizeof(uint32_t)*2] = '\0';
+        data[p] = '\0';
     }
     rd.data = data;
 
-- 
1.7.10.1



More information about the sssd-devel mailing list