Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing calloc failure checks in src/lpmd_util.c #72

Open
ColinIanKing opened this issue Dec 5, 2024 · 0 comments
Open

missing calloc failure checks in src/lpmd_util.c #72

ColinIanKing opened this issue Dec 5, 2024 · 0 comments

Comments

@ColinIanKing
Copy link
Contributor

There are two calloc() calls that are not checked for NULL returns, the following memcpy/memset calls will trigger segmentation faults on the null pointers of proc_stat_prev and proc_stat_cur if calloc fails.

static int parse_proc_stat(void)
{
        FILE *filep;
        int i; 
        int val;
        int count = get_max_online_cpu() + 1;
        int sys_idx = count - 1;
        int size = sizeof(struct proc_stat_info) * count;
 
        filep = fopen (PATH_PROC_STAT, "r");
        if (!filep)
                return 1;
 
        if (!proc_stat_prev)
                proc_stat_prev = calloc(sizeof(struct proc_stat_info), count);
        if (!proc_stat_cur)
                proc_stat_cur = calloc(sizeof(struct proc_stat_info), count);

        memcpy (proc_stat_prev, proc_stat_cur, size);
        memset (proc_stat_cur, 0, size);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant