Commit 72bfde97 by Vicent Martí

Merge pull request #681 from scottjg/solaris-fixes

Fix build/runtime issues on Solaris
parents 27f5b7cf 212eb09d
...@@ -97,7 +97,9 @@ FILE(GLOB SRC_H include/git2/*.h) ...@@ -97,7 +97,9 @@ FILE(GLOB SRC_H include/git2/*.h)
# On Windows use specific platform sources # On Windows use specific platform sources
IF (WIN32 AND NOT CYGWIN) IF (WIN32 AND NOT CYGWIN)
ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_WIN32_WINNT=0x0501) 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() ELSE()
FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c) FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c)
ENDIF () ENDIF ()
......
...@@ -77,7 +77,7 @@ GIT_BEGIN_DECL ...@@ -77,7 +77,7 @@ GIT_BEGIN_DECL
#endif #endif
/** /**
* The maximum length of a git valid git path. * The maximum length of a valid git path.
*/ */
#define GIT_PATH_MAX 4096 #define GIT_PATH_MAX 4096
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with * This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#ifndef INCLUDE_fnmatch__w32_h__ #ifndef INCLUDE_fnmatch__compat_h__
#define INCLUDE_fnmatch__w32_h__ #define INCLUDE_fnmatch__compat_h__
#include "common.h" #include "common.h"
......
...@@ -306,7 +306,7 @@ static int _rmdir_recurs_foreach(void *opaque, git_buf *path) ...@@ -306,7 +306,7 @@ static int _rmdir_recurs_foreach(void *opaque, git_buf *path)
return -1; return -1;
if (p_rmdir(path->ptr) < 0) { 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; return 0;
giterr_set(GITERR_OS, "Could not remove directory '%s'", path->ptr); giterr_set(GITERR_OS, "Could not remove directory '%s'", path->ptr);
......
...@@ -494,7 +494,7 @@ int git_path_direach( ...@@ -494,7 +494,7 @@ int git_path_direach(
{ {
ssize_t wd_len; ssize_t wd_len;
DIR *dir; DIR *dir;
struct dirent de_buf, *de; struct dirent *de, *de_buf;
if (git_path_to_dir(path) < 0) if (git_path_to_dir(path) < 0)
return -1; return -1;
...@@ -506,14 +506,23 @@ int git_path_direach( ...@@ -506,14 +506,23 @@ int git_path_direach(
return -1; 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; int result;
if (is_dot_or_dotdot(de->d_name)) if (is_dot_or_dotdot(de->d_name))
continue; 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; return -1;
}
result = fn(arg, path); result = fn(arg, path);
...@@ -521,11 +530,13 @@ int git_path_direach( ...@@ -521,11 +530,13 @@ int git_path_direach(
if (result < 0) { if (result < 0) {
closedir(dir); closedir(dir);
git__free(de_buf);
return -1; return -1;
} }
} }
closedir(dir); closedir(dir);
git__free(de_buf);
return 0; return 0;
} }
...@@ -537,7 +548,7 @@ int git_path_dirload( ...@@ -537,7 +548,7 @@ int git_path_dirload(
{ {
int error, need_slash; int error, need_slash;
DIR *dir; DIR *dir;
struct dirent de_buf, *de; struct dirent *de, *de_buf;
size_t path_len; size_t path_len;
assert(path != NULL && contents != NULL); assert(path != NULL && contents != NULL);
...@@ -549,11 +560,17 @@ int git_path_dirload( ...@@ -549,11 +560,17 @@ int git_path_dirload(
return -1; 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 += prefix_len;
path_len -= prefix_len; path_len -= prefix_len;
need_slash = (path_len > 0 && path[path_len-1] != '/') ? 1 : 0; 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; char *entry_path;
size_t entry_len; size_t entry_len;
...@@ -573,11 +590,15 @@ int git_path_dirload( ...@@ -573,11 +590,15 @@ int git_path_dirload(
memcpy(&entry_path[path_len + need_slash], de->d_name, entry_len); memcpy(&entry_path[path_len + need_slash], de->d_name, entry_len);
entry_path[path_len + need_slash + entry_len] = '\0'; 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; return -1;
} }
}
closedir(dir); closedir(dir);
git__free(de_buf);
if (error != 0) if (error != 0)
giterr_set(GITERR_OS, "Failed to process directory entry in '%s'", path); giterr_set(GITERR_OS, "Failed to process directory entry in '%s'", path);
......
...@@ -7,7 +7,14 @@ ...@@ -7,7 +7,14 @@
#ifndef INCLUDE_posix__w32_h__ #ifndef INCLUDE_posix__w32_h__
#define 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_lstat(p,b) lstat(p,b)
#define p_readlink(a, b, c) readlink(a, b, c) #define p_readlink(a, b, c) readlink(a, b, c)
...@@ -16,7 +23,6 @@ ...@@ -16,7 +23,6 @@
#define p_mkdir(p,m) mkdir(p, m) #define p_mkdir(p,m) mkdir(p, m)
#define p_fsync(fd) fsync(fd) #define p_fsync(fd) fsync(fd)
#define p_realpath(p, po) realpath(p, po) #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_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__) #define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
#define p_mkstemp(p) mkstemp(p) #define p_mkstemp(p) mkstemp(p)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#define INCLUDE_posix__w32_h__ #define INCLUDE_posix__w32_h__
#include "common.h" #include "common.h"
#include "fnmatch.h" #include "compat/fnmatch.h"
#include "utf-conv.h" #include "utf-conv.h"
GIT_INLINE(int) p_link(const char *old, const char *new) GIT_INLINE(int) p_link(const char *old, const char *new)
......
...@@ -222,3 +222,14 @@ void test_core_dirent__traverse_weird_filenames(void) ...@@ -222,3 +222,14 @@ void test_core_dirent__traverse_weird_filenames(void)
check_counts(&odd); 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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment