diff options
author | Vicent Martà <tanoku@gmail.com> | 2012-05-14 11:01:14 -0700 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2012-05-14 11:01:14 -0700 |
commit | 72bfde97908007ef28b6ab34dcece2aea90c8f53 (patch) | |
tree | 2ca42665f5e7ae0cbd28c54ec2be438bfe1fd10f | |
parent | 27f5b7cfed263a2b0cc01f6f7b6036a1b5ec9ec9 (diff) | |
parent | 212eb09d5fdf04018478eb375df369f9e7e56b66 (diff) | |
download | libgit2-72bfde97908007ef28b6ab34dcece2aea90c8f53.tar.gz |
Merge pull request #681 from scottjg/solaris-fixes
Fix build/runtime issues on Solaris
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | include/git2/common.h | 2 | ||||
-rw-r--r-- | src/compat/fnmatch.c (renamed from src/win32/fnmatch.c) | 0 | ||||
-rw-r--r-- | src/compat/fnmatch.h (renamed from src/win32/fnmatch.h) | 4 | ||||
-rw-r--r-- | src/fileops.c | 2 | ||||
-rw-r--r-- | src/path.c | 33 | ||||
-rw-r--r-- | src/unix/posix.h | 10 | ||||
-rw-r--r-- | src/win32/posix.h | 2 | ||||
-rw-r--r-- | tests-clar/core/dirent.c | 11 |
9 files changed, 54 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 28eefe3b6..d30d09df9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,9 @@ FILE(GLOB SRC_H include/git2/*.h) # On Windows use specific platform sources IF (WIN32 AND NOT CYGWIN) ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_WIN32_WINNT=0x0501) - FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c) + FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c src/compat/*.c) +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") + FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c src/compat/*.c) ELSE() FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c) ENDIF () diff --git a/include/git2/common.h b/include/git2/common.h index a8f8d8e1e..0e9379804 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -77,7 +77,7 @@ GIT_BEGIN_DECL #endif /** - * The maximum length of a git valid git path. + * The maximum length of a valid git path. */ #define GIT_PATH_MAX 4096 diff --git a/src/win32/fnmatch.c b/src/compat/fnmatch.c index 835d811bc..835d811bc 100644 --- a/src/win32/fnmatch.c +++ b/src/compat/fnmatch.c diff --git a/src/win32/fnmatch.h b/src/compat/fnmatch.h index eb7c5f6f7..7faef09b3 100644 --- a/src/win32/fnmatch.h +++ b/src/compat/fnmatch.h @@ -4,8 +4,8 @@ * This file is part of libgit2, distributed under the GNU GPL v2 with * a Linking Exception. For full terms see the included COPYING file. */ -#ifndef INCLUDE_fnmatch__w32_h__ -#define INCLUDE_fnmatch__w32_h__ +#ifndef INCLUDE_fnmatch__compat_h__ +#define INCLUDE_fnmatch__compat_h__ #include "common.h" diff --git a/src/fileops.c b/src/fileops.c index 6b9d78381..ee9d4212d 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -306,7 +306,7 @@ static int _rmdir_recurs_foreach(void *opaque, git_buf *path) return -1; if (p_rmdir(path->ptr) < 0) { - if (removal_type == GIT_DIRREMOVAL_ONLY_EMPTY_DIRS && errno == ENOTEMPTY) + if (removal_type == GIT_DIRREMOVAL_ONLY_EMPTY_DIRS && (errno == ENOTEMPTY || errno == EEXIST)) return 0; giterr_set(GITERR_OS, "Could not remove directory '%s'", path->ptr); diff --git a/src/path.c b/src/path.c index 9f31676b1..84edf6d89 100644 --- a/src/path.c +++ b/src/path.c @@ -494,7 +494,7 @@ int git_path_direach( { ssize_t wd_len; DIR *dir; - struct dirent de_buf, *de; + struct dirent *de, *de_buf; if (git_path_to_dir(path) < 0) return -1; @@ -506,14 +506,23 @@ int git_path_direach( return -1; } - while (p_readdir_r(dir, &de_buf, &de) == 0 && de != NULL) { +#ifdef __sun + de_buf = git__malloc(sizeof(struct dirent) + FILENAME_MAX + 1); +#else + de_buf = git__malloc(sizeof(struct dirent)); +#endif + + while (p_readdir_r(dir, de_buf, &de) == 0 && de != NULL) { int result; if (is_dot_or_dotdot(de->d_name)) continue; - if (git_buf_puts(path, de->d_name) < 0) + if (git_buf_puts(path, de->d_name) < 0) { + closedir(dir); + git__free(de_buf); return -1; + } result = fn(arg, path); @@ -521,11 +530,13 @@ int git_path_direach( if (result < 0) { closedir(dir); + git__free(de_buf); return -1; } } closedir(dir); + git__free(de_buf); return 0; } @@ -537,7 +548,7 @@ int git_path_dirload( { int error, need_slash; DIR *dir; - struct dirent de_buf, *de; + struct dirent *de, *de_buf; size_t path_len; assert(path != NULL && contents != NULL); @@ -549,11 +560,17 @@ int git_path_dirload( return -1; } +#ifdef __sun + de_buf = git__malloc(sizeof(struct dirent) + FILENAME_MAX + 1); +#else + de_buf = git__malloc(sizeof(struct dirent)); +#endif + path += prefix_len; path_len -= prefix_len; need_slash = (path_len > 0 && path[path_len-1] != '/') ? 1 : 0; - while ((error = p_readdir_r(dir, &de_buf, &de)) == 0 && de != NULL) { + while ((error = p_readdir_r(dir, de_buf, &de)) == 0 && de != NULL) { char *entry_path; size_t entry_len; @@ -573,11 +590,15 @@ int git_path_dirload( memcpy(&entry_path[path_len + need_slash], de->d_name, entry_len); entry_path[path_len + need_slash + entry_len] = '\0'; - if (git_vector_insert(contents, entry_path) < 0) + if (git_vector_insert(contents, entry_path) < 0) { + closedir(dir); + git__free(de_buf); return -1; + } } closedir(dir); + git__free(de_buf); if (error != 0) giterr_set(GITERR_OS, "Failed to process directory entry in '%s'", path); diff --git a/src/unix/posix.h b/src/unix/posix.h index 9973acf30..48b492941 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -7,7 +7,14 @@ #ifndef INCLUDE_posix__w32_h__ #define INCLUDE_posix__w32_h__ -#include <fnmatch.h> +#ifndef __sun +# include <fnmatch.h> +# define p_fnmatch(p, s, f) fnmatch(p, s, f) +#else +# include "compat/fnmatch.h" +#endif + +#include <stdio.h> #define p_lstat(p,b) lstat(p,b) #define p_readlink(a, b, c) readlink(a, b, c) @@ -16,7 +23,6 @@ #define p_mkdir(p,m) mkdir(p, m) #define p_fsync(fd) fsync(fd) #define p_realpath(p, po) realpath(p, po) -#define p_fnmatch(p, s, f) fnmatch(p, s, f) #define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a) #define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__) #define p_mkstemp(p) mkstemp(p) diff --git a/src/win32/posix.h b/src/win32/posix.h index 2666fccb4..baa4a3b4e 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -8,7 +8,7 @@ #define INCLUDE_posix__w32_h__ #include "common.h" -#include "fnmatch.h" +#include "compat/fnmatch.h" #include "utf-conv.h" GIT_INLINE(int) p_link(const char *old, const char *new) diff --git a/tests-clar/core/dirent.c b/tests-clar/core/dirent.c index 9c366bf97..5a7859d1b 100644 --- a/tests-clar/core/dirent.c +++ b/tests-clar/core/dirent.c @@ -222,3 +222,14 @@ void test_core_dirent__traverse_weird_filenames(void) check_counts(&odd); } + +/* test filename length limits */ +void test_core_dirent__length_limits(void) +{ + char *big_filename = (char *)git__malloc(FILENAME_MAX + 1); + memset(big_filename, 'a', FILENAME_MAX + 1); + big_filename[FILENAME_MAX] = 0; + + cl_must_fail(p_creat(big_filename, 0666)); + git__free(big_filename); +} |