NULL from parameter for getcwd

posix_api
YuQing 2022-01-29 17:18:13 +08:00
parent 4b9e2d6517
commit 787eb3a7d6
3 changed files with 31 additions and 4 deletions

View File

@ -1,6 +1,7 @@
Version 1.56 2022-01-29
* add function fc_gettid
* function normalize_path: NULL from parameter for getcwd
Version 1.55 2022-01-12
* fastcommon php extension adapt to php 8

View File

@ -3034,13 +3034,11 @@ int normalize_path(const char *from, const char *filename,
const char *start;
const char *last;
const char *end;
char cwd[PATH_MAX];
int up_count;
int path_len;
int i;
if (IS_FILE_RESOURCE(from)) {
from = from + FILE_RESOURCE_TAG_LEN;
}
if (IS_FILE_RESOURCE(filename)) {
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);
}
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, '/');
if (last != NULL) {
end = filename + strlen(filename);

View File

@ -979,7 +979,8 @@ char *format_http_date(time_t t, BufferInfo *buffer);
/** return full path for the filename (the second parameter)
* 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
* full_filename: store the resolved full path filename
* size: the max size of full_filename