[3/3] config: check that there are not unhandled parameters in a config

Submitted by Andrei Vagin on May 9, 2018, 6:28 a.m.

Details

Message ID 20180509062829.23421-3-avagin@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrei Vagin May 9, 2018, 6:28 a.m.
Return an error if we meet unexpected parameters in a config file

Cc: Veronika Kabatova <vkabatov@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/crtools.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/crtools.c b/criu/crtools.c
index 26ae8d11c..5c3b5e503 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -394,20 +394,38 @@  int main(int argc, char *argv[], char *envp[])
 	init_config(argc, argv, &first_count, &second_count);
 
 	while (1) {
+		char **_argv = NULL;
+		int _argc;
+
 		idx = -1;
 
 		switch (state) {
 		case PARSING_GLOBAL_CONF:
-			opt = getopt_long(first_count, global_conf, short_opts, long_opts, &idx);
+			_argc = first_count;
+			_argv = global_conf;
 			break;
 		case PARSING_USER_CONF:
-			opt = getopt_long(second_count, user_conf, short_opts, long_opts, &idx);
+			_argc = second_count;
+			_argv = user_conf;
 			break;
 		case PARSING_ARGV:
-			opt = getopt_long(argc, argv, short_opts, long_opts, &idx);
+			_argc = argc;
+			_argv = argv;
 			break;
+		default:
+			BUG();
 		}
+		opt = getopt_long(_argc, _argv, short_opts, long_opts, &idx);
 		if (opt == -1) {
+			switch (state) {
+			case PARSING_GLOBAL_CONF:
+			case PARSING_USER_CONF:
+				if (optind < _argc) {
+					pr_err("Unknown config parameter: %s\n", _argv[optind]);
+					return -1;
+				}
+				break;
+			}
 			if (state < PARSING_ARGV) {
 				state++;
 				optind = 0;