Skip to content

Commit

Permalink
7731 libdladm`i_dladm_set_single_prop() leaks memory when resetting p…
Browse files Browse the repository at this point in the history
…roperties 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>
  • Loading branch information
Yuri Pankov authored and ahrens committed Jan 11, 2017
1 parent 5f10ef6 commit 4648396
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
52 changes: 30 additions & 22 deletions usr/src/cmd/dladm/Makefile
Expand Up @@ -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
33 changes: 17 additions & 16 deletions usr/src/lib/libdladm/common/linkprop.c
Expand Up @@ -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 :
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4648396

Please sign in to comment.