Patchwork [BUG:1363] portmapper: minor fixes

login
register
Submitter Amar Tumballi
Date 2010-08-14 10:01:38
Message ID <20100814100138.GA12631@gluster.com>
Download mbox | patch
Permalink /patch/4124/
State Accepted
Delegated to: Anand Avati
Headers show

Comments

Amar Tumballi - 2010-08-14 10:01:38
* in bind, initialize the array index to port
* in search, check if brickname is NULL

Signed-off-by: Amar Tumballi <amar@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-pmap.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c
index 12e43ca..b615453 100644
--- a/xlators/mgmt/glusterd/src/glusterd-pmap.c
+++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c
@@ -57,7 +57,7 @@  pmap_port_isfree (int port)
         ret = bind (sock, (struct sockaddr *)&sin, sizeof (sin));
         close (sock);
 
-        return ret == 0 ? 1 : 0;
+        return (ret == 0) ? 1 : 0;
 }
 
 
@@ -113,6 +113,8 @@  pmap_registry_search (xlator_t *this, const char *brickname)
         pmap = pmap_registry_get (this);
 
         for (p = pmap->base_port; p < 65535; p++) {
+                if (!pmap->ports[p].brickname)
+                        continue;
                 if (strcmp (pmap->ports[p].brickname, brickname) == 0) {
                         port = p;
                         break;
@@ -156,11 +158,16 @@  pmap_registry_bind (xlator_t *this, int port, const char *brickname)
 
         pmap = pmap_registry_get (this);
 
+        if (port > 65535)
+                goto out;
+
+        p = port;
         pmap->ports[p].used = 1;
         if (pmap->ports[p].brickname)
                 free (pmap->ports[p].brickname);
         pmap->ports[p].brickname = strdup (brickname);
 
+out:
         return 0;
 }
 
@@ -203,7 +210,9 @@  gluster_pmap_portbybrick (rpcsvc_request_t *req)
 
         port = pmap_registry_search (THIS, brick);
 
-        rsp.op_ret = 0;
+        if (!port)
+                rsp.op_ret = -1;
+
         rsp.port = port;
 
 fail: