summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-02-22 23:46:50 -0500
committerEdward Thomson <ethomson@github.com>2016-02-28 12:38:39 -0500
commit22a19f5b5795153b4c77c75adfae790c3b919be4 (patch)
tree0aa5122a98f379b9ebd11e35b6e8ae48490fd0f8
parent6cc4bac894281d3e80e1861c1ccb0e234cbd9bb0 (diff)
downloadlibgit2-22a19f5b5795153b4c77c75adfae790c3b919be4.tar.gz
git_libgit2_opts: introduce `GIT_OPT_ENABLE_STRICT_OBJECT_CREATION`
-rw-r--r--include/git2/common.h9
-rw-r--r--src/object.c2
-rw-r--r--src/object.h2
-rw-r--r--src/settings.c6
4 files changed, 19 insertions, 0 deletions
diff --git a/include/git2/common.h b/include/git2/common.h
index c26030840..4f43185f8 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -147,6 +147,7 @@ typedef enum {
GIT_OPT_SET_TEMPLATE_PATH,
GIT_OPT_SET_SSL_CERT_LOCATIONS,
GIT_OPT_SET_USER_AGENT,
+ GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
} git_libgit2_opt_t;
/**
@@ -251,6 +252,14 @@ typedef enum {
* > - `user_agent` is the value that will be delivered as the
* > User-Agent header on HTTP requests.
*
+ * * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled)
+ *
+ * > Enable strict input validation when creating new objects
+ * > to ensure that all inputs to the new objects are valid. For
+ * > example, when this is enabled, the parent(s) and tree inputs
+ * > will be validated when creating a new commit. This defaults
+ * > to disabled.
+ *
* @param option Option key
* @param ... value to set the option
* @return 0 on success, <0 on failure
diff --git a/src/object.c b/src/object.c
index b0a8199bc..7f7de9fee 100644
--- a/src/object.c
+++ b/src/object.c
@@ -14,6 +14,8 @@
#include "blob.h"
#include "tag.h"
+bool git_object__strict_input_validation = false;
+
typedef struct {
const char *str; /* type name string */
size_t size; /* size in bytes of the object structure */
diff --git a/src/object.h b/src/object.h
index d187c55b7..358279a3d 100644
--- a/src/object.h
+++ b/src/object.h
@@ -7,6 +7,8 @@
#ifndef INCLUDE_object_h__
#define INCLUDE_object_h__
+extern bool git_object__strict_input_validation;
+
/** Base git object for inheritance */
struct git_object {
git_cached_obj cached;
diff --git a/src/settings.c b/src/settings.c
index d7341abe8..88602bad0 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -14,6 +14,7 @@
#include "sysdir.h"
#include "cache.h"
#include "global.h"
+#include "object.h"
void git_libgit2_version(int *major, int *minor, int *rev)
{
@@ -181,6 +182,11 @@ int git_libgit2_opts(int key, ...)
}
break;
+
+ case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION:
+ git_object__strict_input_validation = (va_arg(ap, int) != 0);
+ break;
+
default:
giterr_set(GITERR_INVALID, "invalid option key");
error = -1;