Commit 7bab2e8fbf302fc7d7732ee92652271015db2a58

Edward Thomson 2016-02-22T23:04:40

git_libgit2_opts: validate key

diff --git a/src/settings.c b/src/settings.c
index da99b59..d7341ab 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -181,6 +181,9 @@ int git_libgit2_opts(int key, ...)
 		}
 
 		break;
+	default:
+		giterr_set(GITERR_INVALID, "invalid option key");
+		error = -1;
 	}
 
 	va_end(ap);
diff --git a/tests/core/opts.c b/tests/core/opts.c
index 3173c64..72408cb 100644
--- a/tests/core/opts.c
+++ b/tests/core/opts.c
@@ -17,3 +17,9 @@ void test_core_opts__readwrite(void)
 
 	cl_assert(new_val == old_val);
 }
+
+void test_core_opts__invalid_option(void)
+{
+	cl_git_fail(git_libgit2_opts(-1, "foobar"));
+}
+