-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some temporary directory handling changes #94
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
#include <sys/syslimits.h> | ||
#endif | ||
|
||
static char _clar_path[4096 + 1]; | ||
#define CLAR_PATH_MAX 4096 | ||
static char _clar_path[CLAR_PATH_MAX]; | ||
|
||
static int | ||
is_valid_tmp_path(const char *path) | ||
|
@@ -35,10 +36,9 @@ find_tmp_path(char *buffer, size_t length) | |
continue; | ||
|
||
if (is_valid_tmp_path(env)) { | ||
#ifdef __APPLE__ | ||
if (length >= PATH_MAX && realpath(env, buffer) != NULL) | ||
return 0; | ||
#endif | ||
if (strlen(env) + 1 > CLAR_PATH_MAX) | ||
return -1; | ||
|
||
strncpy(buffer, env, length - 1); | ||
buffer[length - 1] = '\0'; | ||
return 0; | ||
|
@@ -47,10 +47,6 @@ find_tmp_path(char *buffer, size_t length) | |
|
||
/* If the environment doesn't say anything, try to use /tmp */ | ||
if (is_valid_tmp_path("/tmp")) { | ||
#ifdef __APPLE__ | ||
if (length >= PATH_MAX && realpath("/tmp", buffer) != NULL) | ||
return 0; | ||
#endif | ||
strncpy(buffer, "/tmp", length - 1); | ||
buffer[length - 1] = '\0'; | ||
return 0; | ||
|
@@ -75,6 +71,34 @@ find_tmp_path(char *buffer, size_t length) | |
return -1; | ||
} | ||
|
||
static int canonicalize_tmp_path(char *buffer) | ||
{ | ||
#ifdef _WIN32 | ||
char tmp[CLAR_PATH_MAX]; | ||
DWORD ret; | ||
|
||
ret = GetFullPathName(buffer, CLAR_PATH_MAX, tmp, NULL); | ||
|
||
if (ret == 0 || ret > CLAR_PATH_MAX) | ||
return -1; | ||
|
||
ret = GetLongPathName(tmp, buffer, CLAR_PATH_MAX); | ||
|
||
if (ret == 0 || ret > CLAR_PATH_MAX) | ||
return -1; | ||
|
||
return 0; | ||
#else | ||
char tmp[CLAR_PATH_MAX]; | ||
|
||
if (realpath(buffer, tmp) == NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry a bit that realpath may not be available on all systems, as it is only specified by POSIX.1-2001 and thus not part of C90 itself. And unfortunately we have folks that compile Git on systems that predate POSIX.1-2001 itself. I sometimes wish that some kind of resource existed that provides a matrix of operating system <-> availability of certain features. |
||
return -1; | ||
|
||
strcpy(buffer, tmp); | ||
return 0; | ||
#endif | ||
} | ||
|
||
static void clar_unsandbox(void) | ||
{ | ||
if (_clar_path[0] == '\0') | ||
|
@@ -95,7 +119,8 @@ static int build_sandbox_path(void) | |
|
||
size_t len; | ||
|
||
if (find_tmp_path(_clar_path, sizeof(_clar_path)) < 0) | ||
if (find_tmp_path(_clar_path, sizeof(_clar_path)) < 0 || | ||
canonicalize_tmp_path(_clar_path) < 0) | ||
return -1; | ||
|
||
len = strlen(_clar_path); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intentional that we lose the 4097th byte here?