Skip to content

Commit

Permalink
openrc-shutdown: broadcast: avoid double close
Browse files Browse the repository at this point in the history
Initialize fd and tp to known invalid values, and reset them after
calling close/fclose.

Bug: https://bugs.gentoo.org/923326
Signed-off-by: Mike Gilbert <[email protected]>
  • Loading branch information
floppym committed May 21, 2024
1 parent 3d30b6f commit eddb17b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/openrc-shutdown/broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ void broadcast(char *text)
* These are set across the sigsetjmp call, so they can't be stored on
* the stack, otherwise they might be clobbered.
*/
static int fd;
static FILE *tp;
static int fd = -1;
static FILE *tp = NULL;

getuidtty(&user, &tty);

Expand Down Expand Up @@ -193,10 +193,15 @@ void broadcast(char *text)
}
}
alarm(0);
if (fd >= 0)
close(fd);
if (tp != NULL)
if (tp != NULL) {
fclose(tp);
tp = NULL;
fd = -1; /* fclose will call close for us */
}
if (fd >= 0) {
close(fd);
fd = -1;
}
free(term);
}
endutxent();
Expand Down

0 comments on commit eddb17b

Please sign in to comment.