summaryrefslogtreecommitdiffstats
path: root/src/Hooks/abrt-hook-python.cpp
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2010-01-18 13:19:54 +0100
committerKarel Klic <kklic@redhat.com>2010-01-18 13:19:54 +0100
commit4267cbcc29781ddcac00e259dfe05f3a26fbc2ec (patch)
tree213e47138967f1e7af4ee9ff9a3f2ed861cb5815 /src/Hooks/abrt-hook-python.cpp
parentb2d1bd9e4f387c5a014d3002d741f25421c37aac (diff)
parentb41833ed61f7b579d2a46b26d261616c21a6ae32 (diff)
downloadabrt-4267cbcc29781ddcac00e259dfe05f3a26fbc2ec.tar.gz
abrt-4267cbcc29781ddcac00e259dfe05f3a26fbc2ec.tar.xz
abrt-4267cbcc29781ddcac00e259dfe05f3a26fbc2ec.zip
Merge branch 'master' of git://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/Hooks/abrt-hook-python.cpp')
-rw-r--r--src/Hooks/abrt-hook-python.cpp96
1 files changed, 72 insertions, 24 deletions
diff --git a/src/Hooks/abrt-hook-python.cpp b/src/Hooks/abrt-hook-python.cpp
index 3f79d28..c8a25e3 100644
--- a/src/Hooks/abrt-hook-python.cpp
+++ b/src/Hooks/abrt-hook-python.cpp
@@ -20,27 +20,51 @@
*/
#include <getopt.h>
-#include <unistd.h>
+#include <syslog.h>
/* We can easily get rid of abrtlib (libABRTUtils.so) usage in this file,
* but DebugDump will pull it in anyway */
#include "abrtlib.h"
+#include "hooklib.h"
#include "DebugDump.h"
+#include "ABRTException.h"
#if HAVE_CONFIG_H
# include <config.h>
#endif
#define MAX_BT_SIZE (1024*1024)
+#define MAX_BT_SIZE_STR "1 MB"
static char *pid;
static char *executable;
static char *uuid;
-int main(int argc, char** argv)
+/* Note: "" will return false */
+static bool isxdigit_str(const char *str)
{
- // Error if daemon is not running.
- if (!daemon_is_ok())
- error_msg_and_die("Daemon is not running.");
+ do {
+ if ((*str < '0' || *str > '9') /* not a digit */
+ && ((*str | 0x20) < 'a' || (*str | 0x20) > 'f') /* not A-F or a-f */
+ )
+ {
+ return false;
+ }
+ str++;
+ } while (*str);
+ return true;
+}
+
+static bool printable_str(const char *str)
+{
+ do {
+ if ((unsigned char)(*str) < ' ' || *str == 0x7f)
+ return false;
+ str++;
+ } while (*str);
+ return true;
+}
+int main(int argc, char** argv)
+{
// Parse options
static const struct option longopts[] = {
// name , has_arg , flag, val
@@ -74,49 +98,73 @@ int main(int argc, char** argv)
);
}
}
- if (!pid)
+ if (!pid || !executable || !uuid)
+ goto usage;
+ if (strlen(uuid) > 128 || !isxdigit_str(uuid))
+ goto usage;
+ if (strlen(executable) > PATH_MAX || !printable_str(executable))
goto usage;
-// is it really ok if other params aren't specified? abrtd might get confused...
+ // pid string is sanitized later by xatou()
+
+ openlog("abrt", LOG_PID, LOG_DAEMON);
+ logmode = LOGMODE_SYSLOG;
+
+ // Error if daemon is not running
+ if (!daemon_is_ok())
+ error_msg_and_die("daemon is not running, python crash dump aborted");
+
+ unsigned setting_MaxCrashReportsSize = 0;
+ parse_conf(NULL, &setting_MaxCrashReportsSize, NULL);
+ if (setting_MaxCrashReportsSize > 0)
+ {
+ check_free_space(setting_MaxCrashReportsSize);
+ }
// Read the backtrace from stdin
char *bt = (char*)xmalloc(MAX_BT_SIZE);
ssize_t len = full_read(STDIN_FILENO, bt, MAX_BT_SIZE-1);
if (len < 0)
{
- perror_msg_and_die("Read error");
+ perror_msg_and_die("read error");
}
bt[len] = '\0';
if (len == MAX_BT_SIZE-1)
{
- error_msg("Backtrace size limit exceeded, trimming to 1 MB");
+ error_msg("backtrace size limit exceeded, trimming to " MAX_BT_SIZE_STR);
}
+ // This also checks that pid is a valid numeric string
+ char *cmdline = get_cmdline(xatou(pid)); /* never NULL */
+
// Create directory with the debug dump
char path[PATH_MAX];
snprintf(path, sizeof(path), DEBUG_DUMPS_DIR"/pyhook-%ld-%s",
(long)time(NULL), pid);
-
CDebugDump dd;
- dd.Create(path, geteuid());
- dd.SaveText(FILENAME_ANALYZER, "Python");
- if (executable)
- dd.SaveText(FILENAME_EXECUTABLE, executable);
+ try {
+ dd.Create(path, getuid());
+ } catch (CABRTException &e) {
+ error_msg_and_die("error while creating crash dump %s: %s", path, e.what());
+ }
- pid_t pidt = xatoi(pid);
- char *cmdline = get_cmdline(pidt);
+ dd.SaveText(FILENAME_ANALYZER, "Python");
+ dd.SaveText(FILENAME_EXECUTABLE, executable);
+ dd.SaveText("backtrace", bt);
+ free(bt);
dd.SaveText("cmdline", cmdline);
free(cmdline);
-
- if (uuid)
- dd.SaveText("uuid", uuid);
-
- char uid[sizeof(int) * 3 + 2];
- sprintf(uid, "%d", (int)getuid());
+ dd.SaveText("uuid", uuid);
+ char uid[sizeof(long) * 3 + 2];
+ sprintf(uid, "%lu", (long)getuid());
dd.SaveText("uid", uid);
- dd.SaveText("backtrace", bt);
- free(bt);
dd.Close();
+ log("saved python crash dump of pid %s to %s", pid, path);
+
+ if (setting_MaxCrashReportsSize > 0)
+ {
+ trim_debug_dumps(setting_MaxCrashReportsSize, path);
+ }
return 0;
}