aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-02-08 07:22:09 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:43 -0500
commit11a7ac23a2d7464a74ceb7b97dbae4d5a0208576 (patch)
tree9b4f26d1675ef802b82b01a8780a58d21c17bd2a /arch/um
parent5134d8fea06ab51459fd095d091d1e6f73a44553 (diff)
uml: improved error handling while locating temp dir
* arch/um/os-Linux/mem.c (make_tempfile): Don't deref NULL upon failed malloc. * arch/um/os-Linux/mem.c (make_tempfile): Handle NULL tempdir. Don't let a long tempdir (e.g., via TMPDIR) provoke heap corruption. [ jdike - formatting cleanups, deleted obsolete comment ] Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/um')
-rw-r--r--arch/um/os-Linux/mem.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c
index 38742c21def5..93a11d7edfa0 100644
--- a/arch/um/os-Linux/mem.c
+++ b/arch/um/os-Linux/mem.c
@@ -162,11 +162,6 @@ found:
162 goto out; 162 goto out;
163} 163}
164 164
165/*
166 * This proc still used in tt-mode
167 * (file: kernel/tt/ptproxy/proxy.c, proc: start_debugger).
168 * So it isn't 'static' yet.
169 */
170static int __init make_tempfile(const char *template, char **out_tempname, 165static int __init make_tempfile(const char *template, char **out_tempname,
171 int do_unlink) 166 int do_unlink)
172{ 167{
@@ -175,10 +170,13 @@ static int __init make_tempfile(const char *template, char **out_tempname,
175 170
176 which_tmpdir(); 171 which_tmpdir();
177 tempname = malloc(MAXPATHLEN); 172 tempname = malloc(MAXPATHLEN);
178 if (!tempname) 173 if (tempname == NULL)
179 goto out; 174 return -1;
180 175
181 find_tempdir(); 176 find_tempdir();
177 if ((tempdir == NULL) || (strlen(tempdir) >= MAXPATHLEN))
178 return -1;
179
182 if (template[0] != '/') 180 if (template[0] != '/')
183 strcpy(tempname, tempdir); 181 strcpy(tempname, tempdir);
184 else 182 else
@@ -196,9 +194,8 @@ static int __init make_tempfile(const char *template, char **out_tempname,
196 } 194 }
197 if (out_tempname) { 195 if (out_tempname) {
198 *out_tempname = tempname; 196 *out_tempname = tempname;
199 } else { 197 } else
200 free(tempname); 198 free(tempname);
201 }
202 return fd; 199 return fd;
203out: 200out:
204 free(tempname); 201 free(tempname);