[PATCH] diagnose excess arguments
Jim Meyering
jim at meyering.net
Thu Mar 3 19:43:14 UTC 2011
FYI.
Ignoring excess arguments is a bug. This fixes it:
>From 0a1a0fc83ce20350cb76452b9f520260011e5e20 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Thu, 3 Mar 2011 20:11:56 +0100
Subject: [PATCH] diagnose excess arguments
Before, adding a stray "localhost:9001" without a preceding -d
would be silently accepted, yet that last argument would be
fatally ignored. Now, iwhd diagnoses this.
* rest.c: Include "quote.h"
(main): Diagnose excess arguments.
* bootstrap.conf (gnulib_modules): Add quote.
---
bootstrap.conf | 1 +
lib/.gitignore | 2 ++
rest.c | 6 ++++++
3 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index cf1da8b..2e4cf7f 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -40,6 +40,7 @@ manywarnings
mkstemp
pipe-posix
progname
+quote
quotearg
realloc-gnu
ssize_t
diff --git a/lib/.gitignore b/lib/.gitignore
index af6d24d..bf5c36c 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -58,6 +58,8 @@
/pipe.c
/progname.c
/progname.h
+/quote.c
+/quote.h
/quotearg.c
/quotearg.h
/realloc.c
diff --git a/rest.c b/rest.c
index 3192915..e89e140 100644
--- a/rest.c
+++ b/rest.c
@@ -42,6 +42,7 @@
#include "meta.h"
#include "backend.h"
#include "setup.h"
+#include "quote.h"
#include "replica.h"
#include "template.h"
#include "mpipe.h"
@@ -2249,6 +2250,11 @@ main (int argc, char **argv)
}
args_done:
+ if (optind < argc) {
+ error (0, 0, _("extra operand %s"), quote (argv[optind]));
+ usage (EXIT_FAILURE);
+ }
+
if (!db_port) {
db_port = autostart ? AUTO_MONGOD_PORT : 27017;
}
--
1.7.4.1.21.g4cc62
More information about the iwhd-devel
mailing list