fix invalid pointer access to shared segment.
authorGiannakos Filippos <philipgian@cslab.ece.ntua.gr>
Tue, 13 Dec 2011 14:25:46 +0000 (16:25 +0200)
committerGeorgios D. Tsoukalas <gtsouk@cslab.ece.ntua.gr>
Tue, 13 Dec 2011 14:25:46 +0000 (16:25 +0200)
Also, add locking and copying shared data, for safety.

xseg/xseg/xseg.c

index 61607d8..92b1951 100644 (file)
@@ -94,8 +94,9 @@ static struct xseg_peer *__find_or_load_peer_type(const char *name)
 
 static struct xseg_peer *__get_peer_type(struct xseg *xseg, uint32_t serial)
 {
-       char *name;
+       char name[XSEG_TNAMESIZE];
        struct xseg_peer *type;
+       char (*shared_peer_types)[XSEG_TNAMESIZE];
 
        if (serial >= xseg->max_peer_types) 
                return NULL;
@@ -108,7 +109,12 @@ static struct xseg_peer *__get_peer_type(struct xseg *xseg, uint32_t serial)
        if (serial >= (1 << xseg->config.page_shift) / XSEG_TNAMESIZE)
                return NULL;
 
-       name = xseg->shared->peer_types[serial];
+       __lock_segment(xseg);
+        shared_peer_types = XSEG_TAKE_PTR(xseg->shared->peer_types, xseg->segment);
+        strncpy(name, shared_peer_types[serial], XSEG_TNAMESIZE);
+       name[XSEG_TNAMESIZE-1] = 0;
+       __unlock_segment(xseg);
+       
        if (!*name)
                return NULL;
 
@@ -317,7 +323,7 @@ bind:
 
 success:
        xseg->peer_types[r] = driver;
-       return 0;
+       return r;
 }
 
 long xseg_enable_driver(struct xseg *xseg, const char *name)