Skip to content

Commit

Permalink
Merge pull request #5295 from rgerhards/i5294
Browse files Browse the repository at this point in the history
omusrmsg bugfix: potential double free, which can cause segfault
  • Loading branch information
rgerhards committed Feb 26, 2024
2 parents 3836eba + c7c16b9 commit 9afdd43
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tools/omusrmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,15 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData)

for (j = 0; j < sessions; j++) {
uchar szErr[512];
char *user = NULL, *tty;
char *tty;
const char *user = NULL;
uid_t uid;
struct passwd *pws;

sdRet = sd_session_get_uid(sessions_list[j], &uid);
if (sdRet >= 0) {
pws = getpwuid(uid);
user = pws->pw_name;
user = pws->pw_name; /* DO NOT FREE, OS/LIB internal memory! */

if (user == NULL) {
dbgprintf("failed to get username for userid '%d'\n", uid);
Expand All @@ -303,7 +304,6 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData)
break;
}
if(i == MAXUNAMES) { /* user not found? */
free(user);
free(sessions_list[j]);
continue; /* on to next user! */
}
Expand All @@ -313,14 +313,12 @@ static rsRetVal wallmsg(uchar* pMsg, instanceData *pData)
rs_strerror_r(-sdRet, (char*)szErr, sizeof(szErr));
dbgprintf("get tty for session '%s' failed with [%d]:%s\n",
sessions_list[j], -sdRet, szErr);
free(user);
free(sessions_list[j]);
continue; /* try next session */
}

sendwallmsg(tty, pMsg);

free(user);
free(tty);
free(sessions_list[j]);
}
Expand Down

0 comments on commit 9afdd43

Please sign in to comment.