config_parser: EINVAL with getline() may be recoverable.

It's observed that '-c 2' may cause getline() to set errno to EINVAL
when EOF is encountered. Tune the error checking to get around this edge
case.

Bug: 231362840
Test: new unit test
Change-Id: I52dafcfe791f89d7bb0054e3746a9e1bde952f26
diff --git a/config_parser.c b/config_parser.c
index 4972cf5..9c02c8c 100644
--- a/config_parser.c
+++ b/config_parser.c
@@ -131,8 +131,9 @@
 	/*
 	 * getmultiline() behaves similarly with getline(3). It returns -1
 	 * when read into EOF or the following errors.
+	 * Caveat: EINVAL may happen when EOF is encountered in a valid stream.
 	 */
-	if (errno == EINVAL || errno == ENOMEM) {
+	if ((errno == EINVAL && config_file == NULL) || errno == ENOMEM) {
 		return false;
 	}
 
diff --git a/minijail0_cli_unittest.cc b/minijail0_cli_unittest.cc
index 7b20ecd..51747b3 100644
--- a/minijail0_cli_unittest.cc
+++ b/minijail0_cli_unittest.cc
@@ -605,4 +605,13 @@
   ASSERT_TRUE(parse_args_(argv));
 }
 
+TEST_F(CliTest, conf_parsing_with_dac_override) {
+  std::vector<std::string> argv = {"-c 2", "--config",
+                                   source_path("test/valid.conf"),
+                                   "/bin/sh"};
+
+  ASSERT_TRUE(parse_args_(argv));
+}
+
+
 #endif  // !__ANDROID__