From d9e84b4dc976d3dab53925ac26c024b218daabe3 Mon Sep 17 00:00:00 2001 From: tpearson Date: Thu, 13 Oct 2011 17:58:50 +0000 Subject: Fix detection of executable files by URI This fixes data files being flagged as executable in the run dialog git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1258846 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- .../ebrowsing/plugins/shorturi/kshorturifilter.cpp | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/kcontrol/ebrowsing/plugins/shorturi/kshorturifilter.cpp b/kcontrol/ebrowsing/plugins/shorturi/kshorturifilter.cpp index bee6e99c4..fccaf6b55 100644 --- a/kcontrol/ebrowsing/plugins/shorturi/kshorturifilter.cpp +++ b/kcontrol/ebrowsing/plugins/shorturi/kshorturifilter.cpp @@ -392,10 +392,32 @@ bool KShortURIFilter::filterURI( KURIFilterData& data ) const bool isDir = S_ISDIR( buff.st_mode ); if( !isDir && access ( TQFile::encodeName(path).data(), X_OK) == 0 ) { - //kdDebug() << "Abs path to EXECUTABLE" << endl; - setFilteredURI( data, u ); - setURIType( data, KURIFilterData::EXECUTABLE ); - return true; + // ::access() is not always correct, especially on network file systems + // Verify that we actually have at least one execute permission bit set before flagging the file as executable... + struct stat buffer; + int status; + status = stat(TQFile::encodeName(path).data(), &buffer); + if (status == 0) { + bool is_executable = false; + int file_mode = ((buffer.st_mode & S_IRWXU) >> 6); // User + if (file_mode & 0x1) is_executable = true; + file_mode = file_mode + ((buffer.st_mode & S_IRWXG) >> 3); // Group + if (file_mode & 0x1) is_executable = true; + file_mode = file_mode + ((buffer.st_mode & S_IRWXO) >> 0); // Other + if (file_mode & 0x1) is_executable = true; + if (is_executable == true) { + //kdDebug() << "Abs path to EXECUTABLE" << endl; + setFilteredURI( data, u ); + setURIType( data, KURIFilterData::EXECUTABLE ); + return true; + } + } + else { + //kdDebug() << "Abs path to EXECUTABLE" << endl; + setFilteredURI( data, u ); + setURIType( data, KURIFilterData::EXECUTABLE ); + return true; + } } // Open "uri" as file:/xxx if it is a non-executable local resource. -- cgit v1.2.3