um: Fix len of file in create_pid_file

sizeof gives us the size of the pointer variable, not of the
area it points to. So the number of bytes copied by umid_file_name()
is 8.
We should pass in the correct length of the file buffer.

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
Wen Yang 2020-02-19 21:44:42 +08:00 committed by Richard Weinberger
parent 7d7c056828
commit ba758cfce0
1 changed files with 3 additions and 2 deletions

View File

@ -220,11 +220,12 @@ static void __init create_pid_file(void)
char pid[sizeof("nnnnn\0")], *file; char pid[sizeof("nnnnn\0")], *file;
int fd, n; int fd, n;
file = malloc(strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")); n = strlen(uml_dir) + UMID_LEN + sizeof("/pid\0");
file = malloc(n);
if (!file) if (!file)
return; return;
if (umid_file_name("pid", file, sizeof(file))) if (umid_file_name("pid", file, n))
goto out; goto out;
fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644); fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644);