From owner-freebsd-audit@FreeBSD.ORG Wed Apr 16 17:37:37 2003 Return-Path: Delivered-To: freebsd-audit@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0EE6C37B401 for ; Wed, 16 Apr 2003 17:37:37 -0700 (PDT) Received: from arthur.nitro.dk (port324.ds1-khk.adsl.cybercity.dk [212.242.113.79]) by mx1.FreeBSD.org (Postfix) with ESMTP id 69BF443F93 for ; Wed, 16 Apr 2003 17:37:35 -0700 (PDT) (envelope-from simon@arthur.nitro.dk) Received: by arthur.nitro.dk (Postfix, from userid 1000) id A1B4B10BF82; Thu, 17 Apr 2003 02:37:33 +0200 (CEST) Date: Thu, 17 Apr 2003 02:37:33 +0200 From: "Simon L. Nielsen" To: freebsd-audit@freebsd.org Message-ID: <20030417003732.GA3556@nitro.dk> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="WYTEVAkct0FjGQmd" Content-Disposition: inline User-Agent: Mutt/1.5.4i cc: Soeren Schmidt Subject: atacontrol(8) warns=5 and strcmp cleanup X-BeenThere: freebsd-audit@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: FreeBSD Security Audit List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Apr 2003 00:37:37 -0000 --WYTEVAkct0FjGQmd Content-Type: multipart/mixed; boundary="BXVAT5kNtrzKuDFl" Content-Disposition: inline --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Attached is two patches for atacontrol(8). The first makes it WARNS=3D5 safe. It works on i386 but the only non i386 I have access to an Alpha running 4.7 so there could problems for non i386. A slightly modified version of the patch compiles on the 4.7 Alpha so I think it should be ok. The other patch makes the the strcmp checks more clear. In short : s/!strcmp()/strcmp() =3D=3D 0/ and s/strcmp()/strcmp() !=3D 0/. The generated object file is not changed by either patch. Btw. I posted the patch to -arch since an old PR about WARNS fixes suggested posting here instead of filing a PR. --=20 Simon L. Nielsen --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="atacontrol-warns5.patch" Content-Transfer-Encoding: quoted-printable --- atacontrol.c.orig Thu Apr 17 02:01:59 2003 +++ atacontrol.c Thu Apr 17 02:01:01 2003 @@ -31,6 +31,7 @@ #include #include =20 +#include #include #include #include @@ -38,7 +39,17 @@ #include #include =20 -char * +/* Prototypes */ +const char *mode2str(int mode); +int str2mode(char *str); +void usage(void); +int version(int ver); +void param_print(struct ata_params *parm); +void cap_print(struct ata_params *parm); +int ata_cap_print(int fd, int channel, int device); +int info_print(int fd, int channel, int prchan); + +const char * mode2str(int mode) { switch (mode) { @@ -88,14 +99,14 @@ } =20 int -version(int version) +version(int ver) { int bit; =20 - if (version =3D=3D 0xffff) + if (ver =3D=3D 0xffff) return 0; for (bit =3D 15; bit >=3D 0; bit--) - if (version & (1<support.address48 ? " " : " not "); if (lbasize48) - printf("%lld sectors\n", lbasize48);=09 + printf("%"PRId64" sectors\n", lbasize48); else printf("\n"); =20 Index: Makefile =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 RCS file: /home/ncvs/src/sbin/atacontrol/Makefile,v retrieving revision 1.6 diff -u -d -r1.6 Makefile --- Makefile 4 Dec 2001 02:19:43 -0000 1.6 +++ Makefile 17 Apr 2003 00:15:20 -0000 @@ -1,7 +1,7 @@ #$FreeBSD: src/sbin/atacontrol/Makefile,v 1.6 2001/12/04 02:19:43 obrien E= xp $ =20 PROG=3D atacontrol -WARNS=3D 0 +WARNS=3D 5 MAN=3D atacontrol.8 =20 .include --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="atacontrol-strcmp.patch" Content-Transfer-Encoding: quoted-printable Index: atacontrol.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 RCS file: /home/ncvs/src/sbin/atacontrol/atacontrol.c,v retrieving revision 1.20 retrieving revision 1.20.1002.1 diff -u -d -r1.20 -r1.20.1002.1 --- atacontrol.c 22 Mar 2003 12:18:20 -0000 1.20 +++ atacontrol.c 16 Apr 2003 22:37:49 -0000 1.20.1002.1 @@ -259,12 +259,12 @@ =20 bzero(&iocmd, sizeof(struct ata_cmd)); =20 - if (argc > 2 && strcmp(argv[1], "create")) { + if (argc > 2 && strcmp(argv[1], "create") !=3D 0) { int chan; =20 - if (!strcmp(argv[1], "delete") || - !strcmp(argv[1], "status") || - !strcmp(argv[1], "rebuild")) { + if (strcmp(argv[1], "delete") =3D=3D 0 || + strcmp(argv[1], "status") =3D=3D 0 || + strcmp(argv[1], "rebuild") =3D=3D 0) { if (!(sscanf(argv[2], "%d", &chan) =3D=3D 1 || sscanf(argv[2], "ar%d", &chan) =3D=3D 1)) usage(); @@ -277,7 +277,7 @@ iocmd.channel =3D chan; } =20 - if (!strcmp(argv[1], "list") && argc =3D=3D 2) { + if (strcmp(argv[1], "list") =3D=3D 0 && argc =3D=3D 2) { iocmd.cmd =3D ATAGMAXCHANNEL; if (ioctl(fd, IOCATA, &iocmd) < 0) err(1, "ioctl(ATAGMAXCHANNEL)"); @@ -285,13 +285,13 @@ for (unit =3D 0; unit < maxunit; unit++) info_print(fd, unit, 1); } - else if (!strcmp(argv[1], "info") && argc =3D=3D 3) { + else if (strcmp(argv[1], "info") =3D=3D 0 && argc =3D=3D 3) { info_print(fd, iocmd.channel, 0); } - else if (!strcmp(argv[1], "cap") && argc =3D=3D 4) { + else if (strcmp(argv[1], "cap") =3D=3D 0 && argc =3D=3D 4) { ata_cap_print(fd, iocmd.channel, atoi(argv[3])); } - else if (!strcmp(argv[1], "enclosure") && argc =3D=3D 4) { + else if (strcmp(argv[1], "enclosure") =3D=3D 0 && argc =3D=3D 4) { iocmd.device =3D atoi(argv[3]); iocmd.cmd =3D ATAENCSTAT; if (ioctl(fd, IOCATA, &iocmd) < 0) @@ -302,34 +302,37 @@ (double)iocmd.u.enclosure.v05 / 1000, (double)iocmd.u.enclosure.v12 / 1000); } - else if (!strcmp(argv[1], "detach") && argc =3D=3D 3) { + else if (strcmp(argv[1], "detach") =3D=3D 0 && argc =3D=3D 3) { iocmd.cmd =3D ATADETACH; if (ioctl(fd, IOCATA, &iocmd) < 0) err(1, "ioctl(ATADETACH)"); } - else if (!strcmp(argv[1], "attach") && argc =3D=3D 3) { + else if (strcmp(argv[1], "attach") =3D=3D 0 && argc =3D=3D 3) { iocmd.cmd =3D ATAATTACH; if (ioctl(fd, IOCATA, &iocmd) < 0) err(1, "ioctl(ATAATTACH)"); info_print(fd, iocmd.channel, 0); } - else if (!strcmp(argv[1], "reinit") && argc =3D=3D 3) { + else if (strcmp(argv[1], "reinit") =3D=3D 0 && argc =3D=3D 3) { iocmd.cmd =3D ATAREINIT; if (ioctl(fd, IOCATA, &iocmd) < 0) warn("ioctl(ATAREINIT)"); info_print(fd, iocmd.channel, 0); } - else if (!strcmp(argv[1], "create")) { + else if (strcmp(argv[1], "create") =3D=3D 0) { int disk, dev, offset; =20 iocmd.cmd =3D ATARAIDCREATE; - if (!strcmp(argv[2], "RAID0") || !strcmp(argv[2], "stripe")) + if (strcmp(argv[2], "RAID0") =3D=3D 0 || + strcmp(argv[2], "stripe") =3D=3D 0) iocmd.u.raid_setup.type =3D 1; - if (!strcmp(argv[2], "RAID1") || !strcmp(argv[2],"mirror")) + if (strcmp(argv[2], "RAID1") =3D=3D 0 || + strcmp(argv[2],"mirror") =3D=3D 0) iocmd.u.raid_setup.type =3D 2; - if (!strcmp(argv[2], "RAID0+1")) + if (strcmp(argv[2], "RAID0+1") =3D=3D 0) iocmd.u.raid_setup.type =3D 3; - if (!strcmp(argv[2], "SPAN") || !strcmp(argv[2], "JBOD")) + if (strcmp(argv[2], "SPAN") =3D=3D 0 || + strcmp(argv[2], "JBOD") =3D=3D 0) iocmd.u.raid_setup.type =3D 4; if (!iocmd.u.raid_setup.type) usage(); @@ -355,17 +358,17 @@ else printf("ar%d created\n", iocmd.u.raid_setup.unit); } - else if (!strcmp(argv[1], "delete") && argc =3D=3D 3) { + else if (strcmp(argv[1], "delete") =3D=3D 0 && argc =3D=3D 3) { iocmd.cmd =3D ATARAIDDELETE; if (ioctl(fd, IOCATA, &iocmd) < 0) warn("ioctl(ATARAIDDELETE)"); } - else if (!strcmp(argv[1], "rebuild") && argc =3D=3D 3) { + else if (strcmp(argv[1], "rebuild") =3D=3D 0 && argc =3D=3D 3) { iocmd.cmd =3D ATARAIDREBUILD; if (ioctl(fd, IOCATA, &iocmd) < 0) warn("ioctl(ATARAIDREBUILD)"); } - else if (!strcmp(argv[1], "status") && argc =3D=3D 3) { + else if (strcmp(argv[1], "status") =3D=3D 0 && argc =3D=3D 3) { int i; =20 iocmd.cmd =3D ATARAIDSTATUS; @@ -409,7 +412,7 @@ printf("BROKEN\n"); } } - else if (!strcmp(argv[1], "mode") && (argc =3D=3D 3 || argc =3D=3D 5)) { + else if (strcmp(argv[1], "mode") =3D=3D 0 && (argc =3D=3D 3 || argc =3D= =3D 5)) { if (argc =3D=3D 5) { iocmd.cmd =3D ATASMODE; iocmd.device =3D -1; --BXVAT5kNtrzKuDFl-- --WYTEVAkct0FjGQmd Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE+nfdM8kocFXgPTRwRAnyaAJ9GjRP0qexZii4wJRd/aTO9hK2jzwCgvQBe QkJot4opkkcA2/l2pusSd0A= =2JLY -----END PGP SIGNATURE----- --WYTEVAkct0FjGQmd--