Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 May 2014 11:18:58 +0200
From:      Thomas Quinot <thomas@FreeBSD.ORG>
To:        Gleb Kurtsou <gleb@freebsd.org>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: Proposed extension to stat(1)
Message-ID:  <20140508091858.GA79282@melamine.cuivre.fr.eu.org>
In-Reply-To: <20140508074450.GA2678@reks>
References:  <20140507091213.GA55856@melamine.cuivre.fr.eu.org> <20140508074450.GA2678@reks>

next in thread | previous in thread | raw e-mail | index | archive | help

--b5gNqxB1S1yM7hjW
Content-Type: multipart/mixed; boundary="G4iJoqBmSsgzjUCe"
Content-Disposition: inline


--G4iJoqBmSsgzjUCe
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

* Gleb Kurtsou, 2014-05-08 :

Thanks for the thorough review, Gleb! Much appreciated.

> - why do we care about strlen(file) != sizeof(fh) case?

tcpdump(1) may display handles with additional trailing bytes that are
irrelevant to fhstat(2). It would be inconvenient to require the user to
know about the exact length at which the information needs to be
truncated. It is more helpful to silently discard the excess data.

Attached is a diff vs the committed version (r265591) which I think
addresses all of your remarks. Is there anything else that you
think would need fixing?

Thomas.


--G4iJoqBmSsgzjUCe
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename=d
Content-Transfer-Encoding: quoted-printable

Index: stat.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- stat.1	(r=E9vision 265665)
+++ stat.1	(copie de travail)
@@ -130,6 +130,7 @@
 .Xr fhstat 2
 instead of
 .Xr lstat 2 .
+This requires root privileges.
 .It Fl L
 Use
 .Xr stat 2
Index: stat.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- stat.c	(r=E9vision 265665)
+++ stat.c	(copie de travail)
@@ -186,6 +186,7 @@
 	    char *, size_t,		/* a place to put the output */
 	    int, int, int, int,		/* the parsed format */
 	    int, int);
+int	hex2byte(const char [2]);
 #if HAVE_STRUCT_STAT_ST_FLAGS
 char   *xfflagstostr(unsigned long);
 #endif
@@ -214,7 +215,7 @@
 	lsF =3D 0;
 	fmtchar =3D '\0';
 	usestat =3D 0;
-        nfs_handle =3D 0;
+	nfs_handle =3D 0;
 	nonl =3D 0;
 	quiet =3D 0;
 	linkfail =3D 0;
@@ -327,32 +328,27 @@
 			rc =3D fstat(STDIN_FILENO, &st);
 		} else {
 			int j;
-			char *inval;
=20
 			file =3D argv[0];
 			if (nfs_handle) {
 				rc =3D 0;
-				bzero (&fhnd, sizeof fhnd);
-				j =3D MIN(2 * sizeof fhnd, strlen(file));
-				if (j & 1) {
+				bzero(&fhnd, sizeof(fhnd));
+				j =3D MIN(2 * sizeof(fhnd), strlen(file));
+				if ((j & 1) !=3D 0) {
 					rc =3D -1;
 				} else {
 					while (j) {
-						((char*) &fhnd)[j / 2 - 1] =3D
-						    strtol(&file[j - 2],
-						           &inval, 16);
-						if (inval !=3D NULL) {
-							rc =3D -1;
+						rc =3D hex2byte(&file[j - 2]);
+						if (rc =3D=3D -1)
 							break;
-						}
-						argv[0][j - 2] =3D '\0';
+						((char*) &fhnd)[j / 2 - 1] =3D rc;
 						j -=3D 2;
 					}
-					if (!rc)
-						rc =3D fhstat(&fhnd, &st);
-					else
-						errno =3D EINVAL;
 				}
+				if (rc =3D=3D -1)
+					errno =3D EINVAL;
+				else
+					rc =3D fhstat(&fhnd, &st);
=20
 			} else if (usestat) {
 				/*
@@ -1091,3 +1087,12 @@
=20
 	return (snprintf(buf, blen, lfmt, data));
 }
+
+
+#define hex2nibble(c) (c <=3D '9' ? c - '0' : toupper(c) - 'A' + 10)
+int
+hex2byte(const char c[2]) {
+	if (!(ishexnumber(c[0]) && ishexnumber(c[1])))
+		return -1;
+	return (hex2nibble(c[0]) << 4) + hex2nibble(c[1]);
+}

--G4iJoqBmSsgzjUCe--

--b5gNqxB1S1yM7hjW
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (FreeBSD)

iD8DBQFTa0wAAE1UuDk9JGkRAqX+AJ90UpSfO78nDqCIxEBl6mlx5k2k7QCffj9a
FZ2JO2LYd5wgup1vBvnJuqo=
=MZL1
-----END PGP SIGNATURE-----

--b5gNqxB1S1yM7hjW--



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