Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d72d8467 authored by Suren Baghdasaryan's avatar Suren Baghdasaryan Committed by Gerrit Code Review
Browse files

Merge "lmkd: Fix string null termination in proc_get_size and proc_get_name"

parents 69627e52 ca0790d3
Loading
Loading
Loading
Loading
+11 −10
Original line number Original line Diff line number Diff line
@@ -782,15 +782,15 @@ static int proc_get_size(int pid) {
        close(fd);
        close(fd);
        return -1;
        return -1;
    }
    }
    line[ret] = '\0';


    sscanf(line, "%d %d ", &total, &rss);
    sscanf(line, "%d %d ", &total, &rss);
    close(fd);
    close(fd);
    return rss;
    return rss;
}
}


static char *proc_get_name(int pid) {
static char *proc_get_name(int pid, char *buf, size_t buf_size) {
    char path[PATH_MAX];
    char path[PATH_MAX];
    static char line[LINE_MAX];
    int fd;
    int fd;
    char *cp;
    char *cp;
    ssize_t ret;
    ssize_t ret;
@@ -801,25 +801,24 @@ static char *proc_get_name(int pid) {
    if (fd == -1) {
    if (fd == -1) {
        return NULL;
        return NULL;
    }
    }
    ret = read_all(fd, line, sizeof(line) - 1);
    ret = read_all(fd, buf, buf_size - 1);
    close(fd);
    close(fd);
    if (ret < 0) {
    if (ret < 0) {
        return NULL;
        return NULL;
    }
    }
    buf[ret] = '\0';


    cp = strchr(line, ' ');
    cp = strchr(buf, ' ');
    if (cp) {
    if (cp) {
        *cp = '\0';
        *cp = '\0';
    } else {
        line[ret] = '\0';
    }
    }


    return line;
    return buf;
}
}


static void cmd_procprio(LMKD_CTRL_PACKET packet) {
static void cmd_procprio(LMKD_CTRL_PACKET packet) {
    struct proc *procp;
    struct proc *procp;
    char path[80];
    char path[LINE_MAX];
    char val[20];
    char val[20];
    int soft_limit_mult;
    int soft_limit_mult;
    struct lmk_procprio params;
    struct lmk_procprio params;
@@ -856,7 +855,8 @@ static void cmd_procprio(LMKD_CTRL_PACKET packet) {
    }
    }


    if (use_inkernel_interface) {
    if (use_inkernel_interface) {
        stats_store_taskname(params.pid, proc_get_name(params.pid), kpoll_info.poll_fd);
        stats_store_taskname(params.pid, proc_get_name(params.pid, path, sizeof(path)),
                             kpoll_info.poll_fd);
        return;
        return;
    }
    }


@@ -1660,6 +1660,7 @@ static int kill_one_process(struct proc* procp, int min_oom_score, int kill_reas
    int r;
    int r;
    int result = -1;
    int result = -1;
    struct memory_stat *mem_st;
    struct memory_stat *mem_st;
    char buf[LINE_MAX];


    tgid = proc_get_tgid(pid);
    tgid = proc_get_tgid(pid);
    if (tgid >= 0 && tgid != pid) {
    if (tgid >= 0 && tgid != pid) {
@@ -1667,7 +1668,7 @@ static int kill_one_process(struct proc* procp, int min_oom_score, int kill_reas
        goto out;
        goto out;
    }
    }


    taskname = proc_get_name(pid);
    taskname = proc_get_name(pid, buf, sizeof(buf));
    if (!taskname) {
    if (!taskname) {
        goto out;
        goto out;
    }
    }