Skip to contentSkip to conversation

xfsprogs: misc coverity fixes

PATCH In review Eric Sandeen 3 participants 13 messages Mar 27, 2018

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 xfs_scrub: synchronize error levels & logging

Having only a subset of the five error_levels present in the log_level[] array is asking for trouble when someone tries to __str_log(S_PREEN ...) and overruns the array.

Tie it all together in a single structure that's initialized together to make the mapping more obvious and idiot-proof.

Fixes-coverity-id: 1433618

---

scrub/common.c +13 -20
index 5a37a98..02c6c9d 100644
@@ -56,18 +56,15 @@ xfs_scrub_excessive_errors(
 	return ret;
 }
 
-static const char *err_str[] = {
-	[S_ERROR]	= "Error",
-	[S_WARN]	= "Warning",
-	[S_REPAIR]	= "Repaired",
-	[S_INFO]	= "Info",
-	[S_PREEN]	= "Optimized",
-};
-
-static int log_level[] = {
-	[S_ERROR]	= LOG_ERR,
-	[S_WARN]	= LOG_WARNING,
-	[S_INFO]	= LOG_INFO,
+static struct {
+	const char *string;
+	int loglevel;
+} err_levels[] = {
+	[S_ERROR]  = { .string = "Error",	.loglevel = LOG_ERR },
+	[S_WARN]   = { .string = "Warning",	.loglevel = LOG_WARNING },
+	[S_REPAIR] = { .string = "Repaired",	.loglevel = LOG_WARNING },
+	[S_INFO]   = { .string = "Info",	.loglevel = LOG_INFO },
+	[S_PREEN]  = { .string = "Optimized",	.loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */
@@ -106,8 +103,8 @@ __str_out(
 	if (level == S_PREEN && !debug && !verbose)
 		goto out_record;
 
-	fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-			descr);
+	fprintf(stream, "%s%s: %s: ", stream_start(stream),
+			err_levels[level].string, descr);
 	if (error) {
 		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
 	} else {
@@ -152,10 +149,6 @@ __str_log(
 	char			buf[LOG_BUFSZ];
 	int			sz;
 
-	/* We only want to hear about optimizing when in debug/verbose mode. */
-	if (level == S_PREEN && !debug && !verbose)
-		return;
-
 	/*
 	 * Skip logging if we're being run as a service (presumably the
 	 * service will log stdout/stderr); if we're being run in a non
@@ -168,11 +161,11 @@ __str_log(
 	snprintf(logname, LOGNAME_BUFSZ, "%s@%s", progname, ctx->mntpoint);
 	openlog(logname, LOG_PID, LOG_DAEMON);
 
-	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_str[level]));
+	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_levels[level].string));
 	va_start(args, format);
 	vsnprintf(buf + sz, LOG_BUFSZ - sz, format, args);
 	va_end(args);
-	syslog(log_level[level], "%s", buf);
+	syslog(err_levels[level].loglevel, "%s", buf);
 
 	closelog();
 }
#7 lore raw

PATCH 2/3 xfs_scrub: initialize movon in

In reply to Eric Sandeen

Given the logic in xfs_scrub_connections, it's possible to fail all 3 tests and wind up checking an uninitialized moveon variable at the end. Start out with "true" to avoid this and move on even if all the conditions in the function are false.

Fixes-coverity-id: 1433617

---

scrub/phase5.c +1 -1
index 8e0a1be..5f2a1a7 100644
@@ -244,7 +244,7 @@ xfs_scrub_connections(
 {
 	bool			*pmoveon = arg;
 	char			descr[DESCR_BUFSZ];
-	bool			moveon;
+	bool			moveon = true;
 	xfs_agnumber_t		agno;
 	xfs_agino_t		agino;
 	int			fd = -1;
#2 lore raw

Re: [PATCH 1/3] xfs_scrub: synchronize error levels & logging

In reply to Eric Sandeen
Quoted 45 lines · Eric Sandeen

Having only a subset of the five error_levels present in the log_level[] array is asking for trouble when someone tries to __str_log(S_PREEN ...) and overruns the array.

Tie it all together in a single structure that's initialized together to make the mapping more obvious and idiot-proof.

Fixes-coverity-id: 1433618

---

scrub/common.c +9 -12
index 5a37a98..02c6c9d 100644
@@ -56,18 +56,15 @@ xfs_scrub_excessive_errors(
 	return ret;
 }
 
-static const char *err_str[] = {
-	[S_ERROR]	= "Error",
-	[S_WARN]	= "Warning",
-	[S_REPAIR]	= "Repaired",
-	[S_INFO]	= "Info",
-	[S_PREEN]	= "Optimized",
-};
-
-static int log_level[] = {
-	[S_ERROR]	= LOG_ERR,
-	[S_WARN]	= LOG_WARNING,
-	[S_INFO]	= LOG_INFO,
+static struct {
+	const char *string;
+	int loglevel;
+} err_levels[] = {
+	[S_ERROR]  = { .string = "Error",	.loglevel = LOG_ERR },
+	[S_WARN]   = { .string = "Warning",	.loglevel = LOG_WARNING },
+	[S_REPAIR] = { .string = "Repaired",	.loglevel = LOG_WARNING },
+	[S_INFO]   = { .string = "Info",	.loglevel = LOG_INFO },
+	[S_PREEN]  = { .string = "Optimized",	.loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */

scrub/common.c __str_out( · line 107

Quoted 7 lines
scrub/common.c +2 -2
@@ -106,8 +103,8 @@ __str_out(
 	if (level == S_PREEN && !debug && !verbose)
 		goto out_record;
 
-	fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-			descr);
+	fprintf(stream, "%s%s: %s: ", stream_start(stream),
+			err_levels[level].string, descr);

_(err_levels[level]) here ^^^^^^^^^^^^

Otherwise we end up with:

Error: 你吃饭了吗?你多吃一点。

scrub/common.c __str_log( · line 157

Quoted 10 lines
scrub/common.c +0 -3
 	if (error) {
 		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
 	} else {
@@ -152,10 +149,6 @@ __str_log(
 	char			buf[LOG_BUFSZ];
 	int			sz;
 
-	/* We only want to hear about optimizing when in debug/verbose mode. */
-	if (level == S_PREEN && !debug && !verbose)
-		return;

Why is this being removed?

--D

Quoted 22 lines
scrub/common.c +2 -4
-
 	/*
 	 * Skip logging if we're being run as a service (presumably the
 	 * service will log stdout/stderr); if we're being run in a non
@@ -168,11 +161,11 @@ __str_log(
 	snprintf(logname, LOGNAME_BUFSZ, "%s@%s", progname, ctx->mntpoint);
 	openlog(logname, LOG_PID, LOG_DAEMON);
 
-	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_str[level]));
+	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_levels[level].string));
 	va_start(args, format);
 	vsnprintf(buf + sz, LOG_BUFSZ - sz, format, args);
 	va_end(args);
-	syslog(log_level[level], "%s", buf);
+	syslog(err_levels[level].loglevel, "%s", buf);
 
 	closelog();
 }
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

PATCH 3/3 libfrog: enforce dir XOR blkdev in __fs_table_lookup_mount

In reply to Eric Sandeen

It's not valid to call fs_table_lookup_mount with both dir and blkdev set, but one of them must be supplied. Doing otherwise is a programming error, so catch it with an ASSERT.

Fixes-coverity-id: 1433615
Fixes-coverity-id: 1433616

---

libfrog/paths.c +4 -0
index 318b48f..55cb284 100644
@@ -98,6 +98,10 @@ __fs_table_lookup_mount(
 	char		rpath[PATH_MAX];
 	char		dpath[PATH_MAX];
 
+	/* There can be only one! */
+	ASSERT(dir || blkdev);
+	ASSERT(!(dir && blkdev));
+
 	if (dir && !realpath(dir, dpath))
 		return NULL;
 	if (blkdev && !realpath(blkdev, dpath))
Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] xfs_scrub: initialize movon in

In reply to Eric Sandeen
Quoted 7 lines · Eric Sandeen

Given the logic in xfs_scrub_connections, it's possible to fail all 3 tests and wind up checking an uninitialized moveon variable at the end. Start out with "true" to avoid this and move on even if all the conditions in the function are false.

Fixes-coverity-id: 1433617

Subject line needs typo fix, but otherwise:

--D

Quoted 20 lines

---

scrub/phase5.c +1 -2
index 8e0a1be..5f2a1a7 100644
@@ -244,7 +244,7 @@ xfs_scrub_connections(
 {
 	bool			*pmoveon = arg;
 	char			descr[DESCR_BUFSZ];
-	bool			moveon;
+	bool			moveon = true;
 	xfs_agnumber_t		agno;
 	xfs_agino_t		agino;
 	int			fd = -1;
 
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH 3/3] libfrog: enforce dir XOR blkdev in __fs_table_lookup_mount

In reply to Eric Sandeen
Quoted 8 lines · Eric Sandeen

It's not valid to call fs_table_lookup_mount with both dir and blkdev set, but one of them must be supplied. Doing otherwise is a programming error, so catch it with an ASSERT.

Fixes-coverity-id: 1433615
Fixes-coverity-id: 1433616

Hmmm.... what /is/ the intended behavior if some jerk does fs_table_lookup_mount(NULL) and both arguments are NULL? AFAICT the non-static wrappers will prevent the case where both parameters are specified.

How about:

if (!dir && !blkdev) {
	ASSERT(0);
	return NULL;
}

just after the variable declarations?

--D

Quoted 22 lines

---

libfrog/paths.c +4 -1
index 318b48f..55cb284 100644
@@ -98,6 +98,10 @@ __fs_table_lookup_mount(
 	char		rpath[PATH_MAX];
 	char		dpath[PATH_MAX];
 
+	/* There can be only one! */
+	ASSERT(dir || blkdev);
+	ASSERT(!(dir && blkdev));
+
 	if (dir && !realpath(dir, dpath))
 		return NULL;
 	if (blkdev && !realpath(blkdev, dpath))
 
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH 1/3] xfs_scrub: synchronize error levels & logging

In reply to Darrick J. Wong
Quoted 56 lines · Darrick J. Wong
Quoted 45 lines · Eric Sandeen

Having only a subset of the five error_levels present in the log_level[] array is asking for trouble when someone tries to __str_log(S_PREEN ...) and overruns the array.

Tie it all together in a single structure that's initialized together to make the mapping more obvious and idiot-proof.

Fixes-coverity-id: 1433618

---

scrub/common.c +9 -12
index 5a37a98..02c6c9d 100644
@@ -56,18 +56,15 @@ xfs_scrub_excessive_errors(
 	return ret;
 }
 
-static const char *err_str[] = {
-	[S_ERROR]	= "Error",
-	[S_WARN]	= "Warning",
-	[S_REPAIR]	= "Repaired",
-	[S_INFO]	= "Info",
-	[S_PREEN]	= "Optimized",
-};
-
-static int log_level[] = {
-	[S_ERROR]	= LOG_ERR,
-	[S_WARN]	= LOG_WARNING,
-	[S_INFO]	= LOG_INFO,
+static struct {
+	const char *string;
+	int loglevel;
+} err_levels[] = {
+	[S_ERROR]  = { .string = "Error",	.loglevel = LOG_ERR },
+	[S_WARN]   = { .string = "Warning",	.loglevel = LOG_WARNING },
+	[S_REPAIR] = { .string = "Repaired",	.loglevel = LOG_WARNING },
+	[S_INFO]   = { .string = "Info",	.loglevel = LOG_INFO },
+	[S_PREEN]  = { .string = "Optimized",	.loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */

scrub/common.c __str_out( · line 107

Quoted 7 lines
scrub/common.c +2 -2
@@ -106,8 +103,8 @@ __str_out(
 	if (level == S_PREEN && !debug && !verbose)
 		goto out_record;
 
-	fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-			descr);
+	fprintf(stream, "%s%s: %s: ", stream_start(stream),
+			err_levels[level].string, descr);

_(err_levels[level]) here ^^^^^^^^^^^^

Quoted 3 lines

Otherwise we end up with:

Error: 你吃饭了吗?你多吃一点。

oops

but: _(err_levels[level].string) right ...

Quoted 8 lines
Quoted 8 lines
scrub/common.c +0 -0
 	if (error) {
 		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
 	} else {
@@ -152,10 +149,6 @@ __str_log(
 	char			buf[LOG_BUFSZ];
 	int			sz;
 
Quoted 5 lines

scrub/common.c __str_log( · line 157

Quoted 3 lines
scrub/common.c +0 -3
-	/* We only want to hear about optimizing when in debug/verbose mode. */
-	if (level == S_PREEN && !debug && !verbose)
-		return;

Why is this being removed?

It seemed like a cut & paste error originally but ... it's a leftover, sorry.

-Eric

#4 lore raw

Re: [PATCH 1/3] xfs_scrub: synchronize error levels & logging

Quoted 57 lines · Eric Sandeen
Quoted 56 lines · Darrick J. Wong
Quoted 45 lines · Eric Sandeen

Having only a subset of the five error_levels present in the log_level[] array is asking for trouble when someone tries to __str_log(S_PREEN ...) and overruns the array.

Tie it all together in a single structure that's initialized together to make the mapping more obvious and idiot-proof.

Fixes-coverity-id: 1433618

---

scrub/common.c +9 -12
index 5a37a98..02c6c9d 100644
@@ -56,18 +56,15 @@ xfs_scrub_excessive_errors(
 	return ret;
 }
 
-static const char *err_str[] = {
-	[S_ERROR]	= "Error",
-	[S_WARN]	= "Warning",
-	[S_REPAIR]	= "Repaired",
-	[S_INFO]	= "Info",
-	[S_PREEN]	= "Optimized",
-};
-
-static int log_level[] = {
-	[S_ERROR]	= LOG_ERR,
-	[S_WARN]	= LOG_WARNING,
-	[S_INFO]	= LOG_INFO,
+static struct {
+	const char *string;
+	int loglevel;
+} err_levels[] = {
+	[S_ERROR]  = { .string = "Error",	.loglevel = LOG_ERR },
+	[S_WARN]   = { .string = "Warning",	.loglevel = LOG_WARNING },
+	[S_REPAIR] = { .string = "Repaired",	.loglevel = LOG_WARNING },
+	[S_INFO]   = { .string = "Info",	.loglevel = LOG_INFO },
+	[S_PREEN]  = { .string = "Optimized",	.loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */

scrub/common.c __str_out( · line 107

Quoted 7 lines
scrub/common.c +2 -2
@@ -106,8 +103,8 @@ __str_out(
 	if (level == S_PREEN && !debug && !verbose)
 		goto out_record;
 
-	fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-			descr);
+	fprintf(stream, "%s%s: %s: ", stream_start(stream),
+			err_levels[level].string, descr);

_(err_levels[level]) here ^^^^^^^^^^^^

Quoted 7 lines
Quoted 3 lines

Otherwise we end up with:

Error: 你吃饭了吗?你多吃一点。

oops

but: _(err_levels[level].string) right ...

Er, right.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
scrub/common.c +0 -0
 	if (error) {
 		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
 	} else {
@@ -152,10 +149,6 @@ __str_log(
 	char			buf[LOG_BUFSZ];
 	int			sz;
 
Quoted 7 lines
Quoted 5 lines

scrub/common.c __str_log( · line 157

Quoted 3 lines
scrub/common.c +0 -3
-	/* We only want to hear about optimizing when in debug/verbose mode. */
-	if (level == S_PREEN && !debug && !verbose)
-		return;

Why is this being removed?

It seemed like a cut & paste error originally but ... it's a leftover, sorry.

:)

--D

Quoted 5 lines

-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH v2 1/3 xfs_scrub: synchronize error levels & logging

In reply to Eric Sandeen

Having only a subset of the five error_levels present in the log_level[] array is asking for trouble when someone tries to __str_log(S_PREEN ...) and overruns the array.

Tie it all together in a single structure that's initialized together to make the mapping more obvious and idiot-proof.

Fixes-coverity-id: 1433618

---

V2: i8n, keep test for PREEN in __str_log

scrub/common.c +13 -16
index 5a37a98..02c6c9d 100644
@@ -56,18 +56,15 @@ xfs_scrub_excessive_errors(
 	return ret;
 }
 
-static const char *err_str[] = {
-	[S_ERROR]	= "Error",
-	[S_WARN]	= "Warning",
-	[S_REPAIR]	= "Repaired",
-	[S_INFO]	= "Info",
-	[S_PREEN]	= "Optimized",
-};
-
-static int log_level[] = {
-	[S_ERROR]	= LOG_ERR,
-	[S_WARN]	= LOG_WARNING,
-	[S_INFO]	= LOG_INFO,
+static struct {
+	const char *string;
+	int loglevel;
+} err_levels[] = {
+	[S_ERROR]  = { .string = "Error",	.loglevel = LOG_ERR },
+	[S_WARN]   = { .string = "Warning",	.loglevel = LOG_WARNING },
+	[S_REPAIR] = { .string = "Repaired",	.loglevel = LOG_WARNING },
+	[S_INFO]   = { .string = "Info",	.loglevel = LOG_INFO },
+	[S_PREEN]  = { .string = "Optimized",	.loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */
@@ -106,8 +103,8 @@ __str_out(
 	if (level == S_PREEN && !debug && !verbose)
 		goto out_record;
 
-	fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-			descr);
+	fprintf(stream, "%s%s: %s: ", stream_start(stream),
+			_(err_levels[level].string), descr);
 	if (error) {
 		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
 	} else {
@@ -168,11 +161,11 @@ __str_log(
 	snprintf(logname, LOGNAME_BUFSZ, "%s@%s", progname, ctx->mntpoint);
 	openlog(logname, LOG_PID, LOG_DAEMON);
 
-	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_str[level]));
+	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_levels[level].string));
 	va_start(args, format);
 	vsnprintf(buf + sz, LOG_BUFSZ - sz, format, args);
 	va_end(args);
-	syslog(log_level[level], "%s", buf);
+	syslog(err_levels[level].loglevel, "%s", buf);
 
 	closelog();
 }
#11 lore raw

PATCH v2 3/3 libfrog: handle NULL dir && blkdev in __fs_table_lookup_mount

In reply to Eric Sandeen

If neither dir nor blkdev is set, dpath never gets set, and then gets used (uninitalized) later on.

If we are asked where "nothing" is mounted, just return "nowhere."

Fixes-coverity-id: 1433615
Fixes-coverity-id: 1433616

---

V2: wrappers prevent (sic) both being set, gracefully handle either of the sent-in paths being null.

libfrog/paths.c +3 -0
index 318b48f..c7895e9 100644
@@ -98,6 +98,9 @@ __fs_table_lookup_mount(
 	char		rpath[PATH_MAX];
 	char		dpath[PATH_MAX];
 
+	if (!dir && !blkdev)
+		return NULL;
+
 	if (dir && !realpath(dir, dpath))
 		return NULL;
 	if (blkdev && !realpath(blkdev, dpath))
Reviewed-by on v2 1/3
#6 lore raw

Re: [PATCH 1/3 V2] xfs_scrub: synchronize error levels & logging

In reply to Eric Sandeen
Quoted 10 lines · Eric Sandeen

Having only a subset of the five error_levels present in the log_level[] array is asking for trouble when someone tries to __str_log(S_PREEN ...) and overruns the array.

Tie it all together in a single structure that's initialized together to make the mapping more obvious and idiot-proof.

Fixes-coverity-id: 1433618

Looks ok,

--D

Quoted 65 lines

---

V2: i8n, keep test for PREEN in __str_log

scrub/common.c +13 -17
index 5a37a98..02c6c9d 100644
@@ -56,18 +56,15 @@ xfs_scrub_excessive_errors(
 	return ret;
 }
 
-static const char *err_str[] = {
-	[S_ERROR]	= "Error",
-	[S_WARN]	= "Warning",
-	[S_REPAIR]	= "Repaired",
-	[S_INFO]	= "Info",
-	[S_PREEN]	= "Optimized",
-};
-
-static int log_level[] = {
-	[S_ERROR]	= LOG_ERR,
-	[S_WARN]	= LOG_WARNING,
-	[S_INFO]	= LOG_INFO,
+static struct {
+	const char *string;
+	int loglevel;
+} err_levels[] = {
+	[S_ERROR]  = { .string = "Error",	.loglevel = LOG_ERR },
+	[S_WARN]   = { .string = "Warning",	.loglevel = LOG_WARNING },
+	[S_REPAIR] = { .string = "Repaired",	.loglevel = LOG_WARNING },
+	[S_INFO]   = { .string = "Info",	.loglevel = LOG_INFO },
+	[S_PREEN]  = { .string = "Optimized",	.loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */
@@ -106,8 +103,8 @@ __str_out(
 	if (level == S_PREEN && !debug && !verbose)
 		goto out_record;
 
-	fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-			descr);
+	fprintf(stream, "%s%s: %s: ", stream_start(stream),
+			_(err_levels[level].string), descr);
 	if (error) {
 		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
 	} else {
@@ -168,11 +161,11 @@ __str_log(
 	snprintf(logname, LOGNAME_BUFSZ, "%s@%s", progname, ctx->mntpoint);
 	openlog(logname, LOG_PID, LOG_DAEMON);
 
-	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_str[level]));
+	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_levels[level].string));
 	va_start(args, format);
 	vsnprintf(buf + sz, LOG_BUFSZ - sz, format, args);
 	va_end(args);
-	syslog(log_level[level], "%s", buf);
+	syslog(err_levels[level].loglevel, "%s", buf);
 
 	closelog();
 }
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Reviewed-by on v2 3/3
#12 lore raw

Re: [PATCH 3/3 V2] libfrog: handle NULL dir && blkdev in __fs_table_lookup_mount

In reply to Eric Sandeen
Quoted 9 lines · Eric Sandeen

If neither dir nor blkdev is set, dpath never gets set, and then gets used (uninitalized) later on.

If we are asked where "nothing" is mounted, just return "nowhere."

Fixes-coverity-id: 1433615
Fixes-coverity-id: 1433616

 mmmmmm  mmmm  m    m   mmm         m    m   mm   mmmmm  mmmmm m     m
     #" m"  "m ##  ## m"   "        #    #   ##   #   "# #   "# "m m"
   m#   #    # # ## # #   mm        #mmmm#  #  #  #mmm#" #mmm#"  "#"
  m"    #    # # "" # #    #        #    #  #mm#  #      #        #
 ##mmmm  #mm#  #    #  "mmm"        #    # #    # #      #        #

--D

Quoted 24 lines

---

V2: wrappers prevent (sic) both being set, gracefully handle either of the sent-in paths being null.

libfrog/paths.c +3 -1
index 318b48f..c7895e9 100644
@@ -98,6 +98,9 @@ __fs_table_lookup_mount(
 	char		rpath[PATH_MAX];
 	char		dpath[PATH_MAX];
 
+	if (!dir && !blkdev)
+		return NULL;
+
 	if (dir && !realpath(dir, dpath))
 		return NULL;
 	if (blkdev && !realpath(blkdev, dpath))
 
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html