From e6007747d76477be2e22a008f3b7259091c9812f Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 6 Dec 2008 14:49:56 +0000 Subject: [PATCH] Handle read errors in CFile::Copy() This fixes an endless loop (However, I don't know how it happened). git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1280 726aef4b-f618-498e-8847-2d620e286838 --- FileUtils.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/FileUtils.cpp b/FileUtils.cpp index 905a2443..c7800801 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -200,9 +200,19 @@ bool CFile::Copy(const CString& sOldFileName, const CString& sNewFileName, bool } char szBuf[8192]; - unsigned int len = 0; + int len = 0; while ((len = OldFile.Read(szBuf, 8192))) { + if (len < 0) { + DEBUG_ONLY(cout << "CFile::Copy() failed: " << strerror(errno);) + OldFile.Close(); + + // That file is only a partial copy, get rid of it + NewFile.Close(); + NewFile.Delete(); + + return false; + } NewFile.Write(szBuf, len); }