Skip to content

Commit

Permalink
um: Fix len of file in create_pid_file
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
  • Loading branch information
taskset authored and richardweinberger committed Mar 29, 2020
1 parent 7d7c056 commit ba758cf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions arch/um/os-Linux/umid.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ static void __init create_pid_file(void)
char pid[sizeof("nnnnn\0")], *file;
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)
return;

if (umid_file_name("pid", file, sizeof(file)))
if (umid_file_name("pid", file, n))
goto out;

fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644);
Expand Down

0 comments on commit ba758cf

Please sign in to comment.