Check malloc retval and mark ptr arguments non-null

This commit is contained in:
Daniel Roethlisberger 2014-11-13 22:17:13 +01:00
parent 3579fb6891
commit 2cc353f274
2 changed files with 5 additions and 2 deletions

5
sys.c
View File

@ -217,6 +217,9 @@ sys_proc_info(pid_t pid, char **path, uid_t *uid, gid_t *gid) {
/* fetch process path */
*path = malloc(PROC_PIDPATHINFO_MAXSIZE);
if (!*path) {
return -1;
}
int path_len = proc_pidpath(pid, *path, PROC_PIDPATHINFO_MAXSIZE);
if (path_len == -1) {
free(*path);
@ -238,7 +241,7 @@ char *
sys_user_str(uid_t uid)
{
int bufsize;
if ((bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1) {
if ((bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1) {
log_err_printf("failed to get password bufsize: %s\n",
strerror(errno));
return NULL;

2
sys.h
View File

@ -41,7 +41,7 @@ int sys_pidf_open(const char *) NONNULL(1) WUNRES;
int sys_pidf_write(int) WUNRES;
void sys_pidf_close(int, const char *) NONNULL(2);
int sys_proc_info(pid_t, char **, uid_t *, gid_t *) WUNRES;
int sys_proc_info(pid_t, char **, uid_t *, gid_t *) WUNRES NONNULL(2,3,4);
char * sys_user_str(uid_t) WUNRES MALLOC;
char * sys_group_str(gid_t) WUNRES MALLOC;