From 11db4c500b5811fb621c0d3d3b584d8d4eb579be Mon Sep 17 00:00:00 2001 From: sof <unknown> Date: Mon, 24 Nov 1997 21:21:13 +0000 Subject: [PATCH] [project @ 1997-11-24 21:21:13 by sof] If possible, catch error when opening files for writing to a dangling symlink --- ghc/lib/cbits/openFile.lc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ghc/lib/cbits/openFile.lc b/ghc/lib/cbits/openFile.lc index 73ebe2462ac5..4b92aca8b588 100644 --- a/ghc/lib/cbits/openFile.lc +++ b/ghc/lib/cbits/openFile.lc @@ -67,7 +67,15 @@ StgByteArray how; ghc_errtype = ERR_NOSUCHTHING; ghc_errstr = "file does not exist"; return NULL; - } + } else { + /* If it is a dangling symlink, break off now, too. */ + struct stat st; + if ( lstat(file,&st) == 0) { + ghc_errtype = ERR_NOSUCHTHING; + ghc_errstr = "dangling symlink"; + return NULL; + } + } /* Now try to create it */ while ((fd = open(file, oflags | O_CREAT | O_EXCL, 0666)) < 0) { if (errno == EEXIST) { -- GitLab