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

Andrei Vagin avagin at virtuozzo.com
Wed May 9 09:28:29 MSK 2018


Return an error if we meet unexpected parameters in a config file

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

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;
-- 
2.14.3



More information about the CRIU mailing list