Skip to content

Commit

Permalink
coredump: '% at the end' shouldn't bypass core_uses_pid logic
Browse files Browse the repository at this point in the history
"goto end" should not bypass the "Backward compatibility with
core_uses_pid" code, move this label up.

While at it,

	- It is ugly to copy '|' into cn->corename and then inc
	  the pointer for argv_split().

	  Change format_corename() to increment pat_ptr instead.

	- Remove the dead "if (*pat_ptr == 0)" in format_corename(),
	  we already checked it is not zero.

Signed-off-by: Oleg Nesterov <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Colin Walters <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Lennart Poettering <[email protected]>
Cc: Lucas De Marchi <[email protected]>
Acked-by: Neil Horman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Jul 3, 2013
1 parent 3ceadcf commit 888ffc5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
cn->corename = NULL;
if (expand_corename(cn, core_name_size))
return -ENOMEM;
cn->corename[0] = '\0';

if (ispipe)
++pat_ptr;

/* Repeat as long as we have more pattern to process and more output
space */
while (*pat_ptr) {
if (*pat_ptr != '%') {
if (*pat_ptr == 0)
goto out;
err = cn_printf(cn, "%c", *pat_ptr++);
} else {
switch (*++pat_ptr) {
Expand Down Expand Up @@ -240,6 +242,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
return err;
}

out:
/* Backward compatibility with core_uses_pid:
*
* If core_pattern does not include a %p (as is the default)
Expand All @@ -250,7 +253,6 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
if (err)
return err;
}
out:
return ispipe;
}

Expand Down Expand Up @@ -580,7 +582,7 @@ void do_coredump(siginfo_t *siginfo)
goto fail_dropcount;
}

helper_argv = argv_split(GFP_KERNEL, cn.corename+1, NULL);
helper_argv = argv_split(GFP_KERNEL, cn.corename, NULL);
if (!helper_argv) {
printk(KERN_WARNING "%s failed to allocate memory\n",
__func__);
Expand All @@ -597,7 +599,7 @@ void do_coredump(siginfo_t *siginfo)

argv_free(helper_argv);
if (retval) {
printk(KERN_INFO "Core dump to %s pipe failed\n",
printk(KERN_INFO "Core dump to |%s pipe failed\n",
cn.corename);
goto close_fail;
}
Expand Down

0 comments on commit 888ffc5

Please sign in to comment.