From f77da1ae08512b02a3c50a124f823ed77e53dd64 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 26 Jan 2007 20:30:32 +0000 Subject: Both packageslave.cpp and textedit.cpp have instances of possibly exploitable race conditions associated to files. The big deal is that it is quite typical to use strings of pathnames to track files. But because that does not leverage the filesystem would be attackers may be able to exploit time lags in uses of filesystem functions (like stat and chmod or open) to get files with suspect data into the files that the applications are working with. This commit closes that potential hole even though there are no known exploits. Better safe then sorry. There is no change in the behavior of the apps. --- (limited to 'core/apps') diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 4bbc62b..1c81a55 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -780,22 +780,21 @@ void TextEdit::showEditTools() { /*! unprompted save */ bool TextEdit::save() { - QString name, file; + QString name, file; odebug << "saveAsFile " + currentFileName << oendl; if(currentFileName.isEmpty()) { saveAs(); return false; } - name = currentFileName; - if(doc) { - file = doc->file(); - odebug << "saver file "+file << oendl; - name = doc->name(); - odebug << "File named "+name << oendl; - } else { - file = currentFileName; + if(doc) { + file = doc->file(); + odebug << "saver file "+file << oendl; + name = doc->name(); + odebug << "File named "+name << oendl; + } else { + file = currentFileName; name = QFileInfo(currentFileName).baseName(); - } + } QString rt = editor->text(); if( !rt.isEmpty() ) { @@ -807,36 +806,34 @@ bool TextEdit::save() { struct stat buf; mode_t mode; - stat(file.latin1(), &buf); + QFile f(file); + fstat(f.handle(), &buf); mode = buf.st_mode; if(!fileIs) { doc->setName( name); FileManager fm; if ( !fm.saveFile( *doc, rt ) ) { - QMessageBox::message(tr("Text Edit"),tr("Save Failed")); + QMessageBox::message(tr("Text Edit"),tr("Save Failed")); return false; } } else { odebug << "regular save file" << oendl; - QFile f(file); - if( f.open(IO_WriteOnly)) { - QCString crt = rt.utf8(); - f.writeBlock(crt,crt.length()); - } else { - QMessageBox::message(tr("Text Edit"),tr("Write Failed")); - return false; - } - + if( f.open(IO_WriteOnly)) { + QCString crt = rt.utf8(); + f.writeBlock(crt,crt.length()); + } else { + QMessageBox::message(tr("Text Edit"),tr("Write Failed")); + return false; + } } editor->setEdited( false); edited1=false; edited=false; if(caption().left(1)=="*") - setCaption(caption().right(caption().length()-1)); - + setCaption(caption().right(caption().length()-1)); - chmod( file.latin1(), mode); + fchmod( f.handle(), mode); } return true; } -- cgit v0.9.0.2