Skip to content

Commit

Permalink
um: Fix incorrect assumptions about max pid length
Browse files Browse the repository at this point in the history
pids are no longer limited to 16-bits, bump to 32-bits,
ie. 9 decimal characters.  Additionally sizeof("/") already
returns 2 - ie. it already accounts for trailing zero.

Cc: Jeff Dike <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Anton Ivanov <[email protected]>
Cc: Linux UM Mailing List <[email protected]>
Signed-off-by: Maciej Żenczykowski <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
  • Loading branch information
zenczykowski authored and richardweinberger committed Oct 11, 2020
1 parent 4687615 commit e8a5859
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions arch/um/os-Linux/umid.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int remove_files_and_dir(char *dir)
while ((ent = readdir(directory)) != NULL) {
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
continue;
len = strlen(dir) + sizeof("/") + strlen(ent->d_name) + 1;
len = strlen(dir) + strlen("/") + strlen(ent->d_name) + 1;
if (len > sizeof(file)) {
ret = -E2BIG;
goto out;
Expand Down Expand Up @@ -135,7 +135,7 @@ static int remove_files_and_dir(char *dir)
*/
static inline int is_umdir_used(char *dir)
{
char pid[sizeof("nnnnn\0")], *end, *file;
char pid[sizeof("nnnnnnnnn")], *end, *file;
int dead, fd, p, n, err;
size_t filelen;

Expand Down Expand Up @@ -217,10 +217,10 @@ static int umdir_take_if_dead(char *dir)

static void __init create_pid_file(void)
{
char pid[sizeof("nnnnn\0")], *file;
char pid[sizeof("nnnnnnnnn")], *file;
int fd, n;

n = strlen(uml_dir) + UMID_LEN + sizeof("/pid\0");
n = strlen(uml_dir) + UMID_LEN + sizeof("/pid");
file = malloc(n);
if (!file)
return;
Expand Down

0 comments on commit e8a5859

Please sign in to comment.