Skip to content

Commit

Permalink
uml: improved error handling while locating temp dir
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Jim Meyering authored and Linus Torvalds committed Feb 8, 2008
1 parent 5134d8f commit 11a7ac2
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions arch/um/os-Linux/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ static void which_tmpdir(void)
goto out;
}

/*
* This proc still used in tt-mode
* (file: kernel/tt/ptproxy/proxy.c, proc: start_debugger).
* So it isn't 'static' yet.
*/
static int __init make_tempfile(const char *template, char **out_tempname,
int do_unlink)
{
Expand All @@ -175,10 +170,13 @@ static int __init make_tempfile(const char *template, char **out_tempname,

which_tmpdir();
tempname = malloc(MAXPATHLEN);
if (!tempname)
goto out;
if (tempname == NULL)
return -1;

find_tempdir();
if ((tempdir == NULL) || (strlen(tempdir) >= MAXPATHLEN))
return -1;

if (template[0] != '/')
strcpy(tempname, tempdir);
else
Expand All @@ -196,9 +194,8 @@ static int __init make_tempfile(const char *template, char **out_tempname,
}
if (out_tempname) {
*out_tempname = tempname;
} else {
} else
free(tempname);
}
return fd;
out:
free(tempname);
Expand Down

0 comments on commit 11a7ac2

Please sign in to comment.