From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23286 invoked by alias); 9 Dec 2006 10:01:17 -0000 Received: (qmail 23263 invoked by uid 22791); 9 Dec 2006 10:01:17 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 09 Dec 2006 10:01:12 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id kB9A14La020449; Sat, 9 Dec 2006 11:01:04 +0100 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id kB9A14w2020448; Sat, 9 Dec 2006 11:01:04 +0100 Date: Sat, 09 Dec 2006 10:01:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix hasmntopt Message-ID: <20061209100103.GC3819@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-12/txt/msg00008.txt.bz2 Hi! As the attached testcase shows, hasmntopt wrongly returns a match even if opt option is not present in the list, but some longer option with opt prefix is. Furthermore, it unnecessarily restarts searching for comma at rest, while there can't be any further matches between rest and p. 2006-12-09 Jakub Jelinek * misc/mntent_r.c (__hasmntopt): Check p[optlen] even when p == rest. Start searching for next comma at p rather than rest. * misc/Makefile (tests): Add tst-mntent2. * misc/tst-mntent2.c: New test. --- libc/misc/mntent_r.c.jj 2003-12-18 00:29:02.000000000 +0100 +++ libc/misc/mntent_r.c 2006-12-09 01:19:43.000000000 +0100 @@ -1,5 +1,6 @@ /* Utilities for reading/writing fstab, mtab, etc. - Copyright (C) 1995-2000, 2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1995-2000, 2001, 2002, 2003, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -278,14 +279,11 @@ __hasmntopt (const struct mntent *mnt, c while ((p = strstr (rest, opt)) != NULL) { - if (p == rest - || (p[-1] == ',' - && (p[optlen] == '\0' || - p[optlen] == '=' || - p[optlen] == ','))) + if ((p == rest || p[-1] == ',') + && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ',')) return p; - rest = strchr (rest, ','); + rest = strchr (p, ','); if (rest == NULL) break; ++rest; --- libc/misc/Makefile.jj 2006-06-17 19:00:58.000000000 +0200 +++ libc/misc/Makefile 2006-12-09 10:38:11.000000000 +0100 @@ -78,7 +78,7 @@ endif gpl2lgpl := error.c error.h tests := tst-dirname tst-tsearch tst-fdset tst-efgcvt tst-mntent tst-hsearch \ - tst-error1 tst-pselect tst-insremque + tst-error1 tst-pselect tst-insremque tst-mntent2 ifeq (no,$(cross-compiling)) tests: $(objpfx)tst-error1-mem endif --- libc/misc/tst-mntent2.c.jj 2006-12-09 10:25:10.000000000 +0100 +++ libc/misc/tst-mntent2.c 2006-12-09 10:35:42.000000000 +0100 @@ -0,0 +1,41 @@ +#include +#include +#include + + +int +main (void) +{ + int result = 0; + struct mntent mef; + + mef.mnt_fsname = strdupa ("/dev/sdf6"); + mef.mnt_dir = strdupa ("/some dir"); + mef.mnt_type = strdupa ("ext3"); + mef.mnt_opts = strdupa ("opt1,opt2,noopt=6,rw,norw,brw"); + mef.mnt_freq = 1; + mef.mnt_passno = 2; + +#define TEST(opt, found) \ + if (!!hasmntopt (&mef, (opt)) != (found)) \ + { \ + printf ("Option %s was %sfound\n", (opt), (found) ? "not " : ""); \ + result = 1; \ + } + + TEST ("opt1", 1) + TEST ("opt2", 1) + TEST ("noopt", 1) + TEST ("rw", 1) + TEST ("norw", 1) + TEST ("brw", 1) + TEST ("opt", 0) + TEST ("oopt", 0) + TEST ("w", 0) + TEST ("r", 0) + TEST ("br", 0) + TEST ("nor", 0) + TEST ("or", 0) + + return result; +} Jakub