Made path prettifying functions return GIT_EINVALIDPATH instead of GIT_ERROR.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/src/errors.c b/src/errors.c
index df8b822..41c4a8d 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -19,6 +19,7 @@ static struct {
{GIT_EFLOCKFAIL, "Failed to adquire or release a file lock"},
{GIT_EZLIB, "The Z library failed to inflate/deflate an object's data"},
{GIT_EBUSY, "The queried object is currently busy"},
+ {GIT_EINVALIDPATH, "The path is invalid"},
};
const char *git_strerror(int num)
diff --git a/src/fileops.c b/src/fileops.c
index c2668c5..461dcf0 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -438,7 +438,7 @@ int gitfo_prettify_dir_path(char *buffer_out, const char *path)
*buffer_out ='\0';
len = retrieve_previous_path_component_start(buffer_out_start);
if (len < GIT_SUCCESS)
- return GIT_ERROR;
+ return GIT_EINVALIDPATH;
buffer_out = (char *)buffer_out_start + len;
continue;
@@ -446,7 +446,7 @@ int gitfo_prettify_dir_path(char *buffer_out, const char *path)
/* Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html) */
if (only_dots &&segment_len > 0)
- return GIT_ERROR;
+ return GIT_EINVALIDPATH;
*buffer_out++ = '/';
len++;
@@ -467,7 +467,7 @@ int gitfo_prettify_file_path(char *buffer_out, const char *path)
/* Let's make sure the filename doesn't end with "/", "/." or "/.." */
for (i = 1; path_len > i && i < 4; i++) {
if (!strncmp(path + path_len - i, pattern, i))
- return GIT_ERROR;
+ return GIT_EINVALIDPATH;
}
error = gitfo_prettify_dir_path(buffer_out, path);
@@ -476,7 +476,7 @@ int gitfo_prettify_file_path(char *buffer_out, const char *path)
path_len = strlen(buffer_out);
if (path_len < 2)
- return GIT_ERROR;
+ return GIT_EINVALIDPATH;
/* Remove the trailing slash */
buffer_out[path_len - 1] = '\0';
diff --git a/src/git2/common.h b/src/git2/common.h
index bbeec41..350429f 100644
--- a/src/git2/common.h
+++ b/src/git2/common.h
@@ -136,6 +136,9 @@
/** The index file is not backed up by an existing repository */
#define GIT_EBAREINDEX (GIT_ERROR -14)
+/** The path is invalid */
+#define GIT_EINVALIDPATH (GIT_ERROR - 19)
+
GIT_BEGIN_DECL
/** @} */
GIT_END_DECL