Skip to content

Commit 923bed0

Browse files
oleg-nesterovtorvalds
authored andcommitted
coredump: kill cn_escape(), introduce cn_esc_printf()
The usage of cn_escape() looks really annoying, imho this sequence needs a wrapper. And it is buggy. If cn_printf() does expand_corename() cn_escape() writes to the freed memory. Introduce cn_esc_printf() which hopefully does this all right. It records the index before cn_vprintf(), not "char *" which is no longer valid (in general) after krealloc(). 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>
1 parent 5fe9d8c commit 923bed0

1 file changed

Lines changed: 21 additions & 23 deletions

File tree

‎fs/coredump.c‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,21 @@ static int cn_printf(struct core_name *cn, const char *fmt, ...)
9999
return ret;
100100
}
101101

102-
static void cn_escape(char *str)
102+
static int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
103103
{
104-
for (; *str; str++)
105-
if (*str == '/')
106-
*str = '!';
104+
int cur = cn->used;
105+
va_list arg;
106+
int ret;
107+
108+
va_start(arg, fmt);
109+
ret = cn_vprintf(cn, fmt, arg);
110+
va_end(arg);
111+
112+
for (; cur < cn->used; ++cur) {
113+
if (cn->corename[cur] == '/')
114+
cn->corename[cur] = '!';
115+
}
116+
return ret;
107117
}
108118

109119
static int cn_print_exe_file(struct core_name *cn)
@@ -113,12 +123,8 @@ static int cn_print_exe_file(struct core_name *cn)
113123
int ret;
114124

115125
exe_file = get_mm_exe_file(current->mm);
116-
if (!exe_file) {
117-
char *commstart = cn->corename + cn->used;
118-
ret = cn_printf(cn, "%s (path unknown)", current->comm);
119-
cn_escape(commstart);
120-
return ret;
121-
}
126+
if (!exe_file)
127+
return cn_esc_printf(cn, "%s (path unknown)", current->comm);
122128

123129
pathbuf = kmalloc(PATH_MAX, GFP_TEMPORARY);
124130
if (!pathbuf) {
@@ -132,9 +138,7 @@ static int cn_print_exe_file(struct core_name *cn)
132138
goto free_buf;
133139
}
134140

135-
cn_escape(path);
136-
137-
ret = cn_printf(cn, "%s", path);
141+
ret = cn_esc_printf(cn, "%s", path);
138142

139143
free_buf:
140144
kfree(pathbuf);
@@ -207,22 +211,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
207211
break;
208212
}
209213
/* hostname */
210-
case 'h': {
211-
char *namestart = cn->corename + cn->used;
214+
case 'h':
212215
down_read(&uts_sem);
213-
err = cn_printf(cn, "%s",
216+
err = cn_esc_printf(cn, "%s",
214217
utsname()->nodename);
215218
up_read(&uts_sem);
216-
cn_escape(namestart);
217219
break;
218-
}
219220
/* executable */
220-
case 'e': {
221-
char *commstart = cn->corename + cn->used;
222-
err = cn_printf(cn, "%s", current->comm);
223-
cn_escape(commstart);
221+
case 'e':
222+
err = cn_esc_printf(cn, "%s", current->comm);
224223
break;
225-
}
226224
case 'E':
227225
err = cn_print_exe_file(cn);
228226
break;

0 commit comments

Comments
 (0)