From 338b83a3a7207701d411d0ca876cc4ef9569004b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 11 Dec 2013 01:25:40 -0800 Subject: [PATCH] Ignore write access request if file is a directory. --- src/protocols/rdp/rdp_fs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/protocols/rdp/rdp_fs.c b/src/protocols/rdp/rdp_fs.c index 287da3ef..4f28f52c 100644 --- a/src/protocols/rdp/rdp_fs.c +++ b/src/protocols/rdp/rdp_fs.c @@ -264,6 +264,7 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path, /* Create directory first, if necessary */ if ((create_options & FILE_DIRECTORY_FILE) && (flags & O_CREAT)) { + /* Create directory */ if (mkdir(real_path, S_IRWXU)) { if (errno != EEXIST || (flags & O_EXCL)) { GUAC_RDP_DEBUG(1, "mkdir() failed: %s", strerror(errno)); @@ -281,6 +282,14 @@ int guac_rdp_fs_open(guac_rdp_fs* fs, const char* path, /* Open file */ fd = open(real_path, flags, S_IRUSR | S_IWUSR); + + /* If file open failed as we're trying to write a dir, retry as read-only */ + if (fd == -1 && errno == EISDIR) { + flags &= ~(O_WRONLY | O_RDWR); + flags |= O_RDONLY; + fd = open(real_path, flags, S_IRUSR | S_IWUSR); + } + if (fd == -1) { GUAC_RDP_DEBUG(1, "open() failed: %s", strerror(errno)); return guac_rdp_fs_get_errorcode(errno);