tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Bugs in sbin/mount/pathadj.c?



It seems to me that there are two problems:

	- one minor : with the warning that has been modified and that is less
	pertinent than the "old" one;

	- the other one major: the value returned by realpath(3)
	is lost for the real caller. And testing the value of
	adjusted is wrong since, from the manpage, "adjusted" can
	be defined with the portion of the pathname causing problem.
	And I don't see any caller testing errno...

For the minor bug:

--- /data/m/netbsd_9.3/usr/src/sbin/mount/pathadj.c	2011-02-17 17:57:46.000000000 +0100
+++ pathadj.c	2023-01-21 18:51:35.000000000 +0100
@@ -1,4 +1,4 @@
-/*	$NetBSD: pathadj.c,v 1.2 2011/02/17 16:57:46 pooka Exp $	*/
+/*	$NetBSD: pathadj.c,v 1.3 2020/07/26 08:20:22 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation.  All Rights Reserved.
@@ -37,10 +37,13 @@
 pathadj(const char *input, char *adjusted)
 {
 
-	if (realpath(input, adjusted) == NULL)
+	if (realpath(input, adjusted) == NULL) {
 		warn("Warning: realpath %s", input);
-	if (strncmp(input, adjusted, MAXPATHLEN)) {
-		warnx("\"%s\" is a non-resolved or relative path.", input);
+		return;
+	}
+
+	if (input[0] != '/') {
+		warnx("\"%s\" is a relative path.", input);
 		warnx("using \"%s\" instead.", adjusted);
 	}
 }


An "adjusted" path can perfectly be "/usr/lib/../libexec" so testing
only the first char of "const char *input" against '/' says nothing.

The old way was "too strong" in the sense that "/usr/lib/" resulted in
error (the trailing '/' is removed by realpath(3) so input and adjusted
would differ. But this is minor inconvenience.

The present warning is false. This has no real consequence since this
is not adjpath() that makes anything of the result. But nonetheless, the
modification, for this, seems wrong. And the message for realpath()
failure should be adjusted too.

And this is precisely because pathadj() calls realpath() but doesn't do
anything if realpath(3) is in error, that there is the major problem.

pathadj() should return something on error.
-- 
        Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


Home | Main Index | Thread Index | Old Index