NULL from parameter for getcwd
parent
4b9e2d6517
commit
787eb3a7d6
1
HISTORY
1
HISTORY
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
Version 1.56 2022-01-29
|
Version 1.56 2022-01-29
|
||||||
* add function fc_gettid
|
* add function fc_gettid
|
||||||
|
* function normalize_path: NULL from parameter for getcwd
|
||||||
|
|
||||||
Version 1.55 2022-01-12
|
Version 1.55 2022-01-12
|
||||||
* fastcommon php extension adapt to php 8
|
* fastcommon php extension adapt to php 8
|
||||||
|
|
|
||||||
|
|
@ -3034,13 +3034,11 @@ int normalize_path(const char *from, const char *filename,
|
||||||
const char *start;
|
const char *start;
|
||||||
const char *last;
|
const char *last;
|
||||||
const char *end;
|
const char *end;
|
||||||
|
char cwd[PATH_MAX];
|
||||||
int up_count;
|
int up_count;
|
||||||
int path_len;
|
int path_len;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (IS_FILE_RESOURCE(from)) {
|
|
||||||
from = from + FILE_RESOURCE_TAG_LEN;
|
|
||||||
}
|
|
||||||
if (IS_FILE_RESOURCE(filename)) {
|
if (IS_FILE_RESOURCE(filename)) {
|
||||||
filename = filename + FILE_RESOURCE_TAG_LEN;
|
filename = filename + FILE_RESOURCE_TAG_LEN;
|
||||||
}
|
}
|
||||||
|
|
@ -3049,6 +3047,33 @@ int normalize_path(const char *from, const char *filename,
|
||||||
return snprintf(full_filename, size, "%s", filename);
|
return snprintf(full_filename, size, "%s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (from == NULL) {
|
||||||
|
if (getcwd(cwd, sizeof(cwd)) == NULL) {
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"call getcwd fail, errno: %d, error info: %s",
|
||||||
|
__LINE__, errno, STRERROR(errno));
|
||||||
|
*full_filename = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
path_len = strlen(cwd);
|
||||||
|
if (cwd[path_len - 1] != '/') {
|
||||||
|
if ((path_len + 1) >= sizeof(cwd)) {
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"cwd length is too long, exceeds %d",
|
||||||
|
__LINE__, (int)sizeof(cwd));
|
||||||
|
*full_filename = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cwd[path_len] = '/';
|
||||||
|
cwd[path_len + 1] = '\0';
|
||||||
|
}
|
||||||
|
from = cwd;
|
||||||
|
} else if (IS_FILE_RESOURCE(from)) {
|
||||||
|
from = from + FILE_RESOURCE_TAG_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
last = strrchr(from, '/');
|
last = strrchr(from, '/');
|
||||||
if (last != NULL) {
|
if (last != NULL) {
|
||||||
end = filename + strlen(filename);
|
end = filename + strlen(filename);
|
||||||
|
|
|
||||||
|
|
@ -979,7 +979,8 @@ char *format_http_date(time_t t, BufferInfo *buffer);
|
||||||
|
|
||||||
/** return full path for the filename (the second parameter)
|
/** return full path for the filename (the second parameter)
|
||||||
* parameters:
|
* parameters:
|
||||||
* from: the input full path filename to get base path
|
* from: the input full path filename to get base path,
|
||||||
|
* NULL for current work directory
|
||||||
* filename: the filename to resolve path
|
* filename: the filename to resolve path
|
||||||
* full_filename: store the resolved full path filename
|
* full_filename: store the resolved full path filename
|
||||||
* size: the max size of full_filename
|
* size: the max size of full_filename
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue