mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
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>
This commit is contained in:
parent
5134d8fea0
commit
11a7ac23a2
1 changed files with 6 additions and 9 deletions
|
@ -162,11 +162,6 @@ found:
|
||||||
goto out;
|
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,
|
static int __init make_tempfile(const char *template, char **out_tempname,
|
||||||
int do_unlink)
|
int do_unlink)
|
||||||
{
|
{
|
||||||
|
@ -175,10 +170,13 @@ static int __init make_tempfile(const char *template, char **out_tempname,
|
||||||
|
|
||||||
which_tmpdir();
|
which_tmpdir();
|
||||||
tempname = malloc(MAXPATHLEN);
|
tempname = malloc(MAXPATHLEN);
|
||||||
if (!tempname)
|
if (tempname == NULL)
|
||||||
goto out;
|
return -1;
|
||||||
|
|
||||||
find_tempdir();
|
find_tempdir();
|
||||||
|
if ((tempdir == NULL) || (strlen(tempdir) >= MAXPATHLEN))
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (template[0] != '/')
|
if (template[0] != '/')
|
||||||
strcpy(tempname, tempdir);
|
strcpy(tempname, tempdir);
|
||||||
else
|
else
|
||||||
|
@ -196,9 +194,8 @@ static int __init make_tempfile(const char *template, char **out_tempname,
|
||||||
}
|
}
|
||||||
if (out_tempname) {
|
if (out_tempname) {
|
||||||
*out_tempname = tempname;
|
*out_tempname = tempname;
|
||||||
} else {
|
} else
|
||||||
free(tempname);
|
free(tempname);
|
||||||
}
|
|
||||||
return fd;
|
return fd;
|
||||||
out:
|
out:
|
||||||
free(tempname);
|
free(tempname);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue