summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2016-06-08 14:18:47 +0000
committerngie <ngie@FreeBSD.org>2016-06-08 14:18:47 +0000
commit47cb06bc0c53166cbc76421de660b94a24ea8661 (patch)
tree8271f9eff3aacbd3923acf073bf9f86d9563a08d /lib
parentd1adc82bec6d598d481a6c3192da7bad1e0e95cf (diff)
downloadFreeBSD-src-47cb06bc0c53166cbc76421de660b94a24ea8661.zip
FreeBSD-src-47cb06bc0c53166cbc76421de660b94a24ea8661.tar.gz
MFC r300387,r300388,r300389:
r300387: getnetid(..): consistently fclose fd at the end of the function This mutes a false positive with cppcheck, but also helps eliminate future potential issues with this variable r300388: Call endnetconfig on nc_handle sooner to avoid leaking nc_handle if tmpnconf was NULL This would theoretically happen if the netconfig protocol family and protocol semantics were never matched. CID: 978179 r300389: nis_rpcent: don't leak resultbuf from yp_first(..)/yp_next(..) If the buffer couldn't be adequately resized to accomodate an additional "\n", it would leak resultbuf by breaking from the loop early CID: 1016702
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/rpc/getrpcent.c2
-rw-r--r--lib/libc/rpc/netnamer.c26
-rw-r--r--lib/libc/rpc/rpcb_clnt.c2
3 files changed, 18 insertions, 12 deletions
diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c
index fa404d8..54c403e 100644
--- a/lib/libc/rpc/getrpcent.c
+++ b/lib/libc/rpc/getrpcent.c
@@ -512,6 +512,7 @@ nis_rpcent(void *retval, void *mdata, va_list ap)
sizeof(char *)) {
*errnop = ERANGE;
rv = NS_RETURN;
+ free(resultbuf);
break;
}
@@ -521,6 +522,7 @@ nis_rpcent(void *retval, void *mdata, va_list ap)
if (aliases_size < 1) {
*errnop = ERANGE;
rv = NS_RETURN;
+ free(resultbuf);
break;
}
diff --git a/lib/libc/rpc/netnamer.c b/lib/libc/rpc/netnamer.c
index fce4b4d..6359667 100644
--- a/lib/libc/rpc/netnamer.c
+++ b/lib/libc/rpc/netnamer.c
@@ -253,6 +253,9 @@ getnetid(key, ret)
char *lookup;
int len;
#endif
+ int rv;
+
+ rv = 0;
fd = fopen(NETIDFILE, "r");
if (fd == NULL) {
@@ -263,13 +266,11 @@ getnetid(key, ret)
return (0);
#endif
}
- for (;;) {
- if (fd == NULL)
- return (0); /* getnetidyp brings us here */
+ while (fd != NULL) {
res = fgets(buf, sizeof(buf), fd);
if (res == NULL) {
- fclose(fd);
- return (0);
+ rv = 0;
+ goto done;
}
if (res[0] == '#')
continue;
@@ -292,9 +293,8 @@ getnetid(key, ret)
lookup[len] = 0;
strcpy(ret, lookup);
free(lookup);
- if (fd != NULL)
- fclose(fd);
- return (2);
+ rv = 2;
+ goto done;
#else /* YP */
#ifdef DEBUG
fprintf(stderr,
@@ -320,10 +320,14 @@ getnetid(key, ret)
}
if (strcmp(mkey, key) == 0) {
strcpy(ret, mval);
- fclose(fd);
- return (1);
-
+ rv = 1;
+ goto done;
}
}
}
+
+done:
+ if (fd != NULL)
+ fclose(fd);
+ return (rv);
}
diff --git a/lib/libc/rpc/rpcb_clnt.c b/lib/libc/rpc/rpcb_clnt.c
index 117ee0f..da7f014 100644
--- a/lib/libc/rpc/rpcb_clnt.c
+++ b/lib/libc/rpc/rpcb_clnt.c
@@ -508,6 +508,7 @@ try_nconf:
hostname = IN6_LOCALHOST_STRING;
}
}
+ endnetconfig(nc_handle);
if (tmpnconf == NULL) {
rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
mutex_unlock(&loopnconf_lock);
@@ -515,7 +516,6 @@ try_nconf:
}
loopnconf = getnetconfigent(tmpnconf->nc_netid);
/* loopnconf is never freed */
- endnetconfig(nc_handle);
}
mutex_unlock(&loopnconf_lock);
client = getclnthandle(hostname, loopnconf, NULL);
OpenPOWER on IntegriCloud