mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-21 23:46:27 -05:00
Uses the NOFOLLOW option in open() to ensure to do not follow symbolic links.
This commit is contained in:
parent
322110672e
commit
b299f9d368
3 changed files with 15 additions and 4 deletions
10
handle.c
10
handle.c
|
|
@ -54,7 +54,7 @@ int handle_close_if_different(struct snapraid_handle* handle, struct snapraid_fi
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int handle_ancestor(const char* file)
|
||||
int handle_ancestor(const char* file)
|
||||
{
|
||||
char dir[PATH_MAX];
|
||||
char* c;
|
||||
|
|
@ -111,12 +111,13 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file)
|
|||
}
|
||||
|
||||
/* opening in sequential mode in Windows */
|
||||
handle->f = open(handle->path, O_RDWR | O_CREAT | O_BINARY | O_SEQUENTIAL, 0600);
|
||||
/* do not follow links to ensure to open the real file */
|
||||
handle->f = open(handle->path, O_RDWR | O_CREAT | O_BINARY | O_SEQUENTIAL | O_NOFOLLOW, 0600);
|
||||
|
||||
/* if failed for missing permission */
|
||||
if (handle->f == -1 && errno == EACCES) {
|
||||
/* retry without requesting write permission */
|
||||
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL);
|
||||
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL | O_NOFOLLOW);
|
||||
}
|
||||
|
||||
if (handle->f == -1) {
|
||||
|
|
@ -195,8 +196,9 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file)
|
|||
}
|
||||
|
||||
/* opening in sequential mode in Windows */
|
||||
/* do not follow links to ensure to open the real file */
|
||||
pathprint(handle->path, sizeof(handle->path), "%s%s", handle->disk->dir, file->sub);
|
||||
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL);
|
||||
handle->f = open(handle->path, O_RDONLY | O_BINARY | O_SEQUENTIAL | O_NOFOLLOW);
|
||||
|
||||
if (handle->f == -1) {
|
||||
/* invalidate for error */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue