From owner-freebsd-arch@FreeBSD.ORG Thu May 8 09:19:08 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 58B548D7; Thu, 8 May 2014 09:19:08 +0000 (UTC) Received: from melamine.cuivre.fr.eu.org (houdart.cuivre.fr.eu.org [81.57.40.110]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D213D32C; Thu, 8 May 2014 09:19:07 +0000 (UTC) Received: by melamine.cuivre.fr.eu.org (Postfix, from userid 1000) id 64970FBD6; Thu, 8 May 2014 11:18:58 +0200 (CEST) Date: Thu, 8 May 2014 11:18:58 +0200 From: Thomas Quinot To: Gleb Kurtsou Subject: Re: Proposed extension to stat(1) Message-ID: <20140508091858.GA79282@melamine.cuivre.fr.eu.org> References: <20140507091213.GA55856@melamine.cuivre.fr.eu.org> <20140508074450.GA2678@reks> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="b5gNqxB1S1yM7hjW" Content-Disposition: inline In-Reply-To: <20140508074450.GA2678@reks> X-message-flag: WARNING! Using Outlook can damage your computer. User-Agent: Mutt/1.5.22 (2013-10-16) Cc: freebsd-arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 May 2014 09:19:08 -0000 --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--