Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/flock PR/48351: Dennis Ferguson: Fix incorrect parsi...
details: https://anonhg.NetBSD.org/src/rev/e3b8bde64162
branches: trunk
changeset: 790982:e3b8bde64162
user: christos <christos%NetBSD.org@localhost>
date: Tue Oct 29 16:02:15 2013 +0000
description:
PR/48351: Dennis Ferguson: Fix incorrect parsing of flock flags.
XXX: still flock -s 0 fails with EINVAL, why?
diffstat:
usr.bin/flock/flock.c | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diffs (62 lines):
diff -r 877fcaf34c0b -r e3b8bde64162 usr.bin/flock/flock.c
--- a/usr.bin/flock/flock.c Tue Oct 29 12:27:23 2013 +0000
+++ b/usr.bin/flock/flock.c Tue Oct 29 16:02:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: flock.c,v 1.7 2013/02/07 13:57:40 tron Exp $ */
+/* $NetBSD: flock.c,v 1.8 2013/10/29 16:02:15 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: flock.c,v 1.7 2013/02/07 13:57:40 tron Exp $");
+__RCSID("$NetBSD: flock.c,v 1.8 2013/10/29 16:02:15 christos Exp $");
#include <stdio.h>
#include <string.h>
@@ -149,7 +149,7 @@
main(int argc, char *argv[])
{
int c;
- int lock = LOCK_EX;
+ int lock = 0;
double timeout = 0;
int cls = 0;
int fd = -1;
@@ -170,7 +170,8 @@
debug++;
break;
case 'x':
- if (lock & ~LOCK_NB)
+#define T(l) (lock & ~LOCK_NB) != (l) && (lock & ~LOCK_NB) != 0
+ if (T(LOCK_EX))
goto badlock;
lock |= LOCK_EX;
break;
@@ -178,12 +179,12 @@
lock |= LOCK_NB;
break;
case 's':
- if (lock & ~LOCK_NB)
+ if (T(LOCK_SH))
goto badlock;
lock |= LOCK_SH;
break;
case 'u':
- if (lock & ~LOCK_NB)
+ if (T(LOCK_UN))
goto badlock;
lock |= LOCK_UN;
break;
@@ -205,6 +206,9 @@
argc -= optind;
argv += optind;
+ if ((lock & ~LOCK_NB) == 0)
+ usage("Missing lock type flag");
+
switch (argc) {
case 0:
usage("Missing lock file argument");
Home |
Main Index |
Thread Index |
Old Index