Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22a19f5

Browse files
author
Edward Thomson
committed
git_libgit2_opts: introduce GIT_OPT_ENABLE_STRICT_OBJECT_CREATION
1 parent 6cc4bac commit 22a19f5

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

include/git2/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ typedef enum {
147147
GIT_OPT_SET_TEMPLATE_PATH,
148148
GIT_OPT_SET_SSL_CERT_LOCATIONS,
149149
GIT_OPT_SET_USER_AGENT,
150+
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
150151
} git_libgit2_opt_t;
151152

152153
/**
@@ -251,6 +252,14 @@ typedef enum {
251252
* > - `user_agent` is the value that will be delivered as the
252253
* > User-Agent header on HTTP requests.
253254
*
255+
* * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled)
256+
*
257+
* > Enable strict input validation when creating new objects
258+
* > to ensure that all inputs to the new objects are valid. For
259+
* > example, when this is enabled, the parent(s) and tree inputs
260+
* > will be validated when creating a new commit. This defaults
261+
* > to disabled.
262+
*
254263
* @param option Option key
255264
* @param ... value to set the option
256265
* @return 0 on success, <0 on failure

src/object.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "blob.h"
1515
#include "tag.h"
1616

17+
bool git_object__strict_input_validation = false;
18+
1719
typedef struct {
1820
const char *str; /* type name string */
1921
size_t size; /* size in bytes of the object structure */

src/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef INCLUDE_object_h__
88
#define INCLUDE_object_h__
99

10+
extern bool git_object__strict_input_validation;
11+
1012
/** Base git object for inheritance */
1113
struct git_object {
1214
git_cached_obj cached;

src/settings.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "sysdir.h"
1515
#include "cache.h"
1616
#include "global.h"
17+
#include "object.h"
1718

1819
void git_libgit2_version(int *major, int *minor, int *rev)
1920
{
@@ -181,6 +182,11 @@ int git_libgit2_opts(int key, ...)
181182
}
182183

183184
break;
185+
186+
case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION:
187+
git_object__strict_input_validation = (va_arg(ap, int) != 0);
188+
break;
189+
184190
default:
185191
giterr_set(GITERR_INVALID, "invalid option key");
186192
error = -1;

0 commit comments

Comments
 (0)