summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Pankov <yuri.pankov@nexenta.com>2017-01-11 11:49:23 -0800
committerMatthew Ahrens <mahrens@delphix.com>2017-01-11 11:50:32 -0800
commit4648396c072c3d0c2a1a38afa5f6717799eb1ac7 (patch)
tree88b1ccb2c06a227ac93944bbd846b6312aeeca68
parent5f10ef697f250374b7b917e10961c4e02d4e3112 (diff)
downloadillumos-joyent-4648396c072c3d0c2a1a38afa5f6717799eb1ac7.tar.gz
7731 libdladm`i_dladm_set_single_prop() leaks memory when resetting properties without default value
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com> Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Sebastien Roy <sebastien.roy@delphix.com> Approved by: Matthew Ahrens <mahrens@delphix.com>
-rw-r--r--usr/src/cmd/dladm/Makefile52
-rw-r--r--usr/src/lib/libdladm/common/linkprop.c33
2 files changed, 47 insertions, 38 deletions
diff --git a/usr/src/cmd/dladm/Makefile b/usr/src/cmd/dladm/Makefile
index 143086e26a..43f24b484f 100644
--- a/usr/src/cmd/dladm/Makefile
+++ b/usr/src/cmd/dladm/Makefile
@@ -18,53 +18,61 @@
#
# CDDL HEADER END
#
+
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-PROG= dladm
-CFGFILES= secobj.conf
-
+PROG= dladm
ROOTFS_PROG= $(PROG)
+OBJS= dladm.o
+
+CFGFILES= secobj.conf
ROOTCFGDIR= $(ROOTETC)/dladm
ROOTCFGFILES= $(CFGFILES:%=$(ROOTCFGDIR)/%)
-include ../Makefile.cmd
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/cmd/Makefile.ctf
-XGETFLAGS += -a -x $(PROG).xcl
-LDLIBS += -L$(ROOT)/lib -lsocket
-LDLIBS += -ldladm -ldlpi -lkstat -lsecdb -lbsm -linetutil -ldevinfo
-LDLIBS += $(ZLAZYLOAD) -lrstp $(ZNOLAZYLOAD)
+XGETFLAGS += -a -x $(PROG).xcl
-CERRWARN += -_gcc=-Wno-switch
-CERRWARN += -_gcc=-Wno-unused-label
-CERRWARN += -_gcc=-Wno-uninitialized
+LDLIBS += -L$(ROOT)/lib -lsocket
+LDLIBS += -ldladm -ldlpi -lkstat -lsecdb -lbsm -linetutil -ldevinfo
+LDLIBS += $(ZLAZYLOAD) -lrstp $(ZNOLAZYLOAD)
+
+CERRWARN += -_gcc=-Wno-switch
+CERRWARN += -_gcc=-Wno-unused-label
+CERRWARN += -_gcc=-Wno-uninitialized
# For headers from librstp.
LINTFLAGS += -erroff=E_TRAILING_COMMA_IN_ENUM
+lint := ZLAZYLOAD=
+lint := ZNOLAZYLOAD=
$(ROOTCFGDIR)/secobj.conf := FILEMODE= 660
-lint := ZLAZYLOAD=
-lint := ZNOLAZYLOAD=
-
.KEEP_STATE:
-all: $(ROOTFS_PROG)
+all: $(PROG)
-install: all $(ROOTSBINPROG) $(ROOTCFGDIR) $(ROOTCFGFILES)
- $(RM) $(ROOTUSRSBINPROG)
- -$(SYMLINK) ../../sbin/$(PROG) $(ROOTUSRSBINPROG)
+$(PROG): $(OBJS)
+ $(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
clean:
+ $(RM) $(OBJS)
+
+install: all $(ROOTSBINPROG) $(ROOTCFGDIR) $(ROOTCFGFILES)
+ $(RM) $(ROOTUSRSBINPROG)
+ -$(SYMLINK) ../../sbin/$(PROG) $(ROOTUSRSBINPROG)
-lint: lint_PROG
+lint: lint_PROG
$(ROOTCFGDIR):
- $(INS.dir)
+ $(INS.dir)
$(ROOTCFGDIR)/%: $(ROOTCFGDIR) %
- $(INS.file)
+ $(INS.file)
-include ../Makefile.targ
+include $(SRC)/cmd/Makefile.targ
diff --git a/usr/src/lib/libdladm/common/linkprop.c b/usr/src/lib/libdladm/common/linkprop.c
index 140c5e4edd..d861b7eb7d 100644
--- a/usr/src/lib/libdladm/common/linkprop.c
+++ b/usr/src/lib/libdladm/common/linkprop.c
@@ -940,31 +940,33 @@ i_dladm_set_single_prop(dladm_handle_t handle, datalink_id_t linkid,
cnt = val_cnt;
} else {
- boolean_t defval = B_FALSE;
+ boolean_t defval;
if (pdp->pd_defval.vd_name == NULL)
return (DLADM_STATUS_NOTSUP);
cnt = 1;
defval = (strlen(pdp->pd_defval.vd_name) > 0);
- if ((pdp->pd_flags & PD_CHECK_ALLOC) != 0 || defval) {
- if ((vdp = calloc(1, sizeof (val_desc_t))) == NULL)
- return (DLADM_STATUS_NOMEM);
-
- if (defval) {
- (void) memcpy(vdp, &pdp->pd_defval,
- sizeof (val_desc_t));
- } else if (pdp->pd_check != NULL) {
- status = pdp->pd_check(handle, pdp, linkid,
- prop_val, &cnt, flags, &vdp, media);
- if (status != DLADM_STATUS_OK)
- goto done;
- }
- } else {
+ if ((pdp->pd_flags & PD_CHECK_ALLOC) == 0 && !defval) {
status = i_dladm_getset_defval(handle, pdp, linkid,
media, flags);
return (status);
}
+
+ vdp = calloc(1, sizeof (val_desc_t));
+ if (vdp == NULL)
+ return (DLADM_STATUS_NOMEM);
+
+ if (defval) {
+ (void) memcpy(vdp, &pdp->pd_defval,
+ sizeof (val_desc_t));
+ } else if (pdp->pd_check != NULL) {
+ needfree = ((pdp->pd_flags & PD_CHECK_ALLOC) != 0);
+ status = pdp->pd_check(handle, pdp, linkid, prop_val,
+ &cnt, flags, &vdp, media);
+ if (status != DLADM_STATUS_OK)
+ goto done;
+ }
}
if (pdp->pd_flags & PD_AFTER_PERM)
status = (flags & DLADM_OPT_PERSIST) ? DLADM_STATUS_OK :
@@ -4113,7 +4115,6 @@ get_flowctl(dladm_handle_t handle, prop_desc_t *pdp,
static dladm_status_t
i_dladm_set_private_prop(dladm_handle_t handle, datalink_id_t linkid,
const char *prop_name, char **prop_val, uint_t val_cnt, uint_t flags)
-
{
int i, slen;
int bufsize = 0;