Commit 888ffc5923e4343a78575918ab781e85fa22d244

Authored by Oleg Nesterov
Committed by Linus Torvalds
1 parent 3ceadcf6d4

coredump: '% at the end' shouldn't bypass core_uses_pid logic

"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 <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Colin Walters <walters@verbum.org>
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Lennart Poettering <mzxreary@0pointer.de>
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 7 additions and 5 deletions Side-by-side Diff

... ... @@ -165,13 +165,15 @@
165 165 cn->corename = NULL;
166 166 if (expand_corename(cn, core_name_size))
167 167 return -ENOMEM;
  168 + cn->corename[0] = '\0';
168 169  
  170 + if (ispipe)
  171 + ++pat_ptr;
  172 +
169 173 /* Repeat as long as we have more pattern to process and more output
170 174 space */
171 175 while (*pat_ptr) {
172 176 if (*pat_ptr != '%') {
173   - if (*pat_ptr == 0)
174   - goto out;
175 177 err = cn_printf(cn, "%c", *pat_ptr++);
176 178 } else {
177 179 switch (*++pat_ptr) {
... ... @@ -240,6 +242,7 @@
240 242 return err;
241 243 }
242 244  
  245 +out:
243 246 /* Backward compatibility with core_uses_pid:
244 247 *
245 248 * If core_pattern does not include a %p (as is the default)
... ... @@ -250,7 +253,6 @@
250 253 if (err)
251 254 return err;
252 255 }
253   -out:
254 256 return ispipe;
255 257 }
256 258  
... ... @@ -580,7 +582,7 @@
580 582 goto fail_dropcount;
581 583 }
582 584  
583   - helper_argv = argv_split(GFP_KERNEL, cn.corename+1, NULL);
  585 + helper_argv = argv_split(GFP_KERNEL, cn.corename, NULL);
584 586 if (!helper_argv) {
585 587 printk(KERN_WARNING "%s failed to allocate memory\n",
586 588 __func__);
... ... @@ -597,7 +599,7 @@
597 599  
598 600 argv_free(helper_argv);
599 601 if (retval) {
600   - printk(KERN_INFO "Core dump to %s pipe failed\n",
  602 + printk(KERN_INFO "Core dump to |%s pipe failed\n",
601 603 cn.corename);
602 604 goto close_fail;
603 605 }