summaryrefslogtreecommitdiffstats
path: root/lib/Utils/DebugDump.cpp
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2009-10-30 23:47:27 +0100
committerKarel Klic <kklic@redhat.com>2009-10-30 23:47:27 +0100
commitd0962176b885a32b1c5aecd5ac3c0d23447c3d09 (patch)
treea876da5cefe940264b97d35e80b9cd3a7ef7e64a /lib/Utils/DebugDump.cpp
parent0843e750bce39df0e69e4962b3c7f98294d0739b (diff)
parent276a9017d63445dd322f9a93ff34e67cbdf97dc9 (diff)
downloadabrt-d0962176b885a32b1c5aecd5ac3c0d23447c3d09.tar.gz
abrt-d0962176b885a32b1c5aecd5ac3c0d23447c3d09.tar.xz
abrt-d0962176b885a32b1c5aecd5ac3c0d23447c3d09.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib/Utils/DebugDump.cpp')
-rw-r--r--lib/Utils/DebugDump.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index ecd6d05b..5017d868 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -23,7 +23,7 @@
#include <iostream>
#include <sstream>
#include <sys/utsname.h>
-#include <magic.h>
+//#include <magic.h>
#include "abrtlib.h"
#include "DebugDump.h"
#include "ABRTException.h"
@@ -290,8 +290,10 @@ static void DeleteFileDir(const std::string& pDir)
}
}
-static bool IsTextFile(const std::string& pName)
+static bool IsTextFile(const char *name)
{
+/* This idiotic library thinks that file containing just "0" is not text (!!)
+
magic_t m = magic_open(MAGIC_MIME_TYPE);
if (m == NULL)
@@ -320,6 +322,24 @@ static bool IsTextFile(const std::string& pName)
magic_close(m);
return isText;
+ */
+ int fd = open(name, O_RDONLY);
+ if (fd < 0)
+ return false;
+
+ unsigned char buf[4*1024];
+ int r = full_read(fd, buf, sizeof(buf));
+ close(fd);
+
+ while (--r >= 0)
+ {
+ if (buf[r] >= 0x7f)
+ return false;
+ /* Among control chars, only '\t','\n' etc are allowed */
+ if (buf[r] < ' ' && !isspace(buf[r]))
+ return false;
+ }
+ return true;
}
static std::string RemoveBackSlashes(const std::string& pDir)
@@ -532,7 +552,7 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool
std::string fullname = m_sDebugDumpDir + "/" + dent->d_name;
pFileName = dent->d_name;
- if (IsTextFile(fullname))
+ if (IsTextFile(fullname.c_str()))
{
LoadText(dent->d_name, pContent);
pIsTextFile = true;