nfs_parse_url: initialize memory
[deb_libnfs.git] / lib / libnfs.c
index b6bd822ebabf2eda89eef9b04ecee4a845055c91..4eb18512900c420aaeb279c9f2e24317e8977074 100644 (file)
@@ -173,6 +173,18 @@ char *nfs_get_error(struct nfs_context *nfs)
        return rpc_get_error(nfs->rpc);
 };
 
+int rpc_set_context_args(struct rpc_context *rpc, char *arg, char *val)
+{
+       if (!strncmp(arg, "tcp-syncnt", 10)) {
+               rpc_set_tcp_syncnt(rpc, atoi(val));
+       } else if (!strncmp(arg, "uid", 3)) {
+               rpc_set_uid(rpc, atoi(val));
+       } else if (!strncmp(arg, "gid", 3)) {
+               rpc_set_gid(rpc, atoi(val));
+       }
+       return 0;
+}
+
 static struct nfs_url *nfs_parse_url(struct nfs_context *nfs, const char *url, int dir, int incomplete)
 {
        struct nfs_url *urls;
@@ -189,6 +201,7 @@ static struct nfs_url *nfs_parse_url(struct nfs_context *nfs, const char *url, i
                return NULL;
        }
 
+       memset(urls, 0x00, sizeof(struct nfs_url));
        urls->server = strdup(url + 6);
        if (urls->server == NULL) {
                nfs_destroy_url(urls);
@@ -265,11 +278,6 @@ flags:
                }
        }
 
-       if (urls->server && strlen(urls->server) <= 1) {
-               free(urls->server);
-               urls->server = NULL;
-       }
-
        while (flagsp != NULL && *(flagsp+1) != 0) {
                strp = flagsp + 1;
                flagsp = strchr(strp, '&');
@@ -280,16 +288,16 @@ flags:
                if (strp2) {
                        *strp2 = 0;
                        strp2++;
-                       if (!strncmp(strp, "tcp-syncnt", 10)) {
-                               rpc_set_tcp_syncnt(nfs->rpc, atoi(strp2));
-                       } else if (!strncmp(strp, "uid", 3)) {
-                               rpc_set_uid(nfs->rpc, atoi(strp2));
-                       } else if (!strncmp(strp, "gid", 3)) {
-                               rpc_set_gid(nfs->rpc, atoi(strp2));
-                       }
+                       rpc_set_context_args(nfs_get_rpc_context(nfs),
+                                       strp, strp2);
                }
        }
 
+       if (urls->server && strlen(urls->server) <= 1) {
+               free(urls->server);
+               urls->server = NULL;
+       }
+
        return urls;
 }