Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Aug 2014 14:57:22 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r270213 - stable/9/cddl/contrib/opensolaris/lib/libdtrace/common
Message-ID:  <201408201457.s7KEvMOF046705@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Wed Aug 20 14:57:21 2014
New Revision: 270213
URL: http://svnweb.freebsd.org/changeset/base/270213

Log:
  MFC r269524:
  Preserve the errno value of an ioctl before calling free(3). Previously,
  errno was very occasionally being clobbered, resulting in a bogus error from
  dt_consume() and thus an error from dtrace(1).

Modified:
  stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
  stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c
  stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c
Directory Properties:
  stable/9/cddl/contrib/opensolaris/   (props changed)
  stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/   (props changed)

Modified: stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
==============================================================================
--- stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c	Wed Aug 20 14:57:20 2014	(r270212)
+++ stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c	Wed Aug 20 14:57:21 2014	(r270213)
@@ -2555,7 +2555,7 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, d
 {
 	dtrace_optval_t size;
 	dtrace_bufdesc_t *buf = dt_zalloc(dtp, sizeof (*buf));
-	int error;
+	int error, rval;
 
 	if (buf == NULL)
 		return (-1);
@@ -2574,7 +2574,6 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, d
 #else
 	if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &buf) == -1) {
 #endif
-		dt_put_buf(dtp, buf);
 		/*
 		 * If we failed with ENOENT, it may be because the
 		 * CPU was unconfigured -- this is okay.  Any other
@@ -2582,10 +2581,12 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, d
 		 */
 		if (errno == ENOENT) {
 			*bufp = NULL;
-			return (0);
-		}
+			rval = 0;
+		} else
+			rval = dt_set_errno(dtp, errno);
 
-		return (dt_set_errno(dtp, errno));
+		dt_put_buf(dtp, buf);
+		return (rval);
 	}
 
 	error = dt_unring_buf(dtp, buf);

Modified: stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c
==============================================================================
--- stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c	Wed Aug 20 14:57:20 2014	(r270212)
+++ stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c	Wed Aug 20 14:57:21 2014	(r270213)
@@ -39,7 +39,7 @@
 static int
 dt_strdata_add(dtrace_hdl_t *dtp, dtrace_recdesc_t *rec, void ***data, int *max)
 {
-	int maxformat;
+	int maxformat, rval;
 	dtrace_fmtdesc_t fmt;
 	void *result;
 
@@ -63,8 +63,9 @@ dt_strdata_add(dtrace_hdl_t *dtp, dtrace
 		return (dt_set_errno(dtp, EDT_NOMEM));
 
 	if (dt_ioctl(dtp, DTRACEIOC_FORMAT, &fmt) == -1) {
+		rval = dt_set_errno(dtp, errno);
 		free(fmt.dtfd_string);
-		return (dt_set_errno(dtp, errno));
+		return (rval);
 	}
 
 	while (rec->dtrd_format > (maxformat = *max)) {

Modified: stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c
==============================================================================
--- stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c	Wed Aug 20 14:57:20 2014	(r270212)
+++ stable/9/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c	Wed Aug 20 14:57:21 2014	(r270213)
@@ -184,7 +184,7 @@ dtrace_go(dtrace_hdl_t *dtp)
 {
 	dtrace_enable_io_t args;
 	void *dof;
-	int err;
+	int error, r;
 
 	if (dtp->dt_active)
 		return (dt_set_errno(dtp, EINVAL));
@@ -206,11 +206,12 @@ dtrace_go(dtrace_hdl_t *dtp)
 
 	args.dof = dof;
 	args.n_matched = 0;
-	err = dt_ioctl(dtp, DTRACEIOC_ENABLE, &args);
+	r = dt_ioctl(dtp, DTRACEIOC_ENABLE, &args);
+	error = errno;
 	dtrace_dof_destroy(dtp, dof);
 
-	if (err == -1 && (errno != ENOTTY || dtp->dt_vector == NULL))
-		return (dt_set_errno(dtp, errno));
+	if (r == -1 && (error != ENOTTY || dtp->dt_vector == NULL))
+		return (dt_set_errno(dtp, error));
 
 	if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) {
 		if (errno == EACCES)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408201457.s7KEvMOF046705>