From dfcdd535528e1aed6d0041b6557b12db06501c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sat, 22 Dec 2012 19:51:30 +0000 Subject: [PATCH] [INTERPRETER] * NEW: Check at startup that temporary directories are really directories and not symbolic links. git-svn-id: svn://localhost/gambas/trunk@5464 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_api.c | 2 -- main/share/gb_file_temp.h | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/main/gbx/gbx_api.c b/main/gbx/gbx_api.c index b7caaaf1e..30e8c3153 100644 --- a/main/gbx/gbx_api.c +++ b/main/gbx/gbx_api.c @@ -2248,8 +2248,6 @@ bool GB_StatFile(const char *path, GB_FILE_STAT *info, bool follow) END_CATCH_ERROR } -// TODO: don't accept directories! - char *GB_RealFileName(const char *name, int len) { char *path = STRING_conv_file_name(name, len); diff --git a/main/share/gb_file_temp.h b/main/share/gb_file_temp.h index 2ae67b964..7d806ad3d 100644 --- a/main/share/gb_file_temp.h +++ b/main/share/gb_file_temp.h @@ -180,15 +180,18 @@ void FILE_remove_temp_file(void) void FILE_init(void) { + struct stat info; + FILE_remove_temp_file(); snprintf(file_buffer, sizeof(file_buffer), FILE_TEMP_PREFIX, (int)getuid()); mkdir(file_buffer, S_IRWXU); - if (chown(file_buffer, getuid(), getgid()) || chmod(file_buffer, S_IRWXU) == 0) + + if (lstat(file_buffer, &info) == 0 && S_ISDIR(info.st_mode) && chown(file_buffer, getuid(), getgid()) == 0 && chmod(file_buffer, S_IRWXU) == 0) { snprintf(file_buffer, sizeof(file_buffer), FILE_TEMP_DIR, (int)getuid(), (int)getpid()); mkdir(file_buffer, S_IRWXU); - if (chown(file_buffer, getuid(), getgid()) || chmod(file_buffer, S_IRWXU) == 0) + if (lstat(file_buffer, &info) == 0 && S_ISDIR(info.st_mode) && chown(file_buffer, getuid(), getgid()) == 0 && chmod(file_buffer, S_IRWXU) == 0) return; }