summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-06-07 16:48:16 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2011-06-07 16:48:16 +0200
commitb0811dd6938902401a378b83ee9b123be7e7c228 (patch)
treeed3fa0887b07de34ff5d9cdd043c2f838b024006
parent2fa751f6d98995e73db4d0edd0d22b9560281644 (diff)
downloadabrt-b0811dd6938902401a378b83ee9b123be7e7c228.tar.gz
abrt-b0811dd6938902401a378b83ee9b123be7e7c228.tar.xz
abrt-b0811dd6938902401a378b83ee9b123be7e7c228.zip
abrt-hook-ccpp: never pass %h corename spec and avoid passing %e if possible
This closes bz#679720 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--abrt-ccpp.init15
-rw-r--r--src/hooks/abrt-hook-ccpp.c28
2 files changed, 33 insertions, 10 deletions
diff --git a/abrt-ccpp.init b/abrt-ccpp.init
index 1676cb04..7f236237 100644
--- a/abrt-ccpp.init
+++ b/abrt-ccpp.init
@@ -25,9 +25,13 @@ verbose=false
LOCK="/var/lock/subsys/abrt-ccpp"
PATTERN_FILE="/proc/sys/kernel/core_pattern"
+SAVED_PATTERN_DIR="/var/run/abrt"
SAVED_PATTERN_FILE="/var/run/abrt/saved_core_pattern"
HOOK_BIN="/usr/libexec/abrt-hook-ccpp"
-PATTERN="|$HOOK_BIN /var/spool/abrt %s %c %p %u %g %t %h %e"
+# Must match percent_specifiers[] order in abrt-hook-ccpp.c:
+PATTERN="|$HOOK_BIN /var/spool/abrt %s %c %p %u %g %t %e"
+# Same, but with bogus "executable name" parameter
+PATTERN1="|$HOOK_BIN /var/spool/abrt %s %c %p %u %g %t e"
# core_pipe_limit specifies how many dump_helpers can run at the same time
# 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing
@@ -57,10 +61,19 @@ start() {
cur=`cat "$PATTERN_FILE"`
cur_first=`printf "%s" "$cur" | sed 's/ .*//'`
+ # Is there a %e (executable name) in old pattern anywhere?
+ if test x"${cur#.*%e}" = x"${cur}"; then
+ # No. Can use PATTERN with less risk of overflow
+ # on expansion (executable names can be LONG).
+ # Overflow would cause kernel to abort coredump. BAD.
+ PATTERN="$PATTERN1"
+ fi
+
$verbose && printf "cur:'%s'\n" "$cur"
# Is it already installed?
if test x"$cur_first" != x"|$HOOK_BIN"; then # no
# It is not installed
+ mkdir -p -- "$SAVED_PATTERN_DIR"
printf "%s\n" "$cur" >"$SAVED_PATTERN_FILE"
# Install new handler
$verbose && printf "Installing to %s:'%s'\n" "$PATTERN_FILE" "$PATTERN"
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
index e912e0ac..0c6bccd2 100644
--- a/src/hooks/abrt-hook-ccpp.c
+++ b/src/hooks/abrt-hook-ccpp.c
@@ -169,12 +169,14 @@ static char* get_cwd(pid_t pid)
* %u - uid
* %g - gid
* %t - UNIX time of dump
- * %h - hostname
* %e - executable filename
+ * %h - hostname
* %% - output one "%"
*/
-/* Must match CORE_PATTERN order in daemon! */
-static const char percent_specifiers[] = "%scpugthe";
+/* Hook must be installed with exactly the same sequence of %c specifiers.
+ * Last one, %h, may be omitted (we can find it out).
+ */
+static const char percent_specifiers[] = "%scpugteh";
static char *core_basename = (char*) "core";
static int open_user_core(const char *user_pwd, uid_t uid, pid_t pid, char **percent_values)
@@ -306,13 +308,13 @@ int main(int argc, char** argv)
{
struct stat sb;
- if (argc < 10) /* no argv[9]? */
+ if (argc < 9) /* no argv[8]? */
{
- /* percent specifier: %s %c %p %u %g %t %h %e */
- /* argv: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] */
+ /* percent specifier: %s %c %p %u %g %t %e %h */
+ /* argv: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] */
// [OLD_PATTERN] is deprecated, so removing it from help:
- //error_msg_and_die("Usage: %s DUMPDIR SIGNO CORE_SIZE_LIMIT PID UID GID TIME HOSTNAME BINARY_NAME [OLD_PATTERN]", argv[0]);
- error_msg_and_die("Usage: %s DUMPDIR SIGNO CORE_SIZE_LIMIT PID UID GID TIME HOSTNAME BINARY_NAME", argv[0]);
+ //error_msg_and_die("Usage: %s DUMPDIR SIGNO CORE_SIZE_LIMIT PID UID GID TIME BINARY_NAME [HOSTNAME [OLD_PATTERN]]", argv[0]);
+ error_msg_and_die("Usage: %s DUMPDIR SIGNO CORE_SIZE_LIMIT PID UID GID TIME BINARY_NAME [HOSTNAME]", argv[0]);
}
/* Not needed on 2.6.30.
@@ -362,7 +364,15 @@ int main(int argc, char** argv)
argv[10] = NULL; /* don't use old way to pass OLD_PATTERN */
}
}
- if (argv[10]) /* OLD_PATTERN (deprecated) */
+
+ struct utsname uts;
+ if (!argv[9]) /* no HOSTNAME? */
+ {
+ uname(&uts);
+ argv[9] = uts.nodename;
+ }
+ else /* argv[9]=HOSTNAME exists.*/
+ if (argv[10]) /* OLD_PATTERN? (deprecated) */
{
char *buf = (char*) xzalloc(strlen(argv[10]) / 2 + 2);
char *end = hex2bin(buf, argv[10], strlen(argv[10]));