Skip to content

Commit 9f53930

Browse files
committed
fixup! Avoid comparing this to NULL
Turns out that these comparisons are actually essential: otherwise e.g. `kill <pid>` will simply segfault if `<pid>` does not refer to an MSYS2 process (see git-for-windows/git#1316 for a real-world bug report). We *have* to compile this code with -Wno-error=nonnull-compare. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent ce9c714 commit 9f53930

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

winsup/cygwin/fhandler_dsp.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ fhandler_dev_dsp::Audio_out::buf_info (audio_buf_info *p,
500500
int rate, int bits, int channels)
501501
{
502502
p->fragstotal = MAX_BLOCKS;
503-
if (dev_)
503+
if (this && dev_)
504504
{
505505
/* If the device is running we use the internal values,
506506
possibly set from the wave file. */
@@ -957,7 +957,7 @@ fhandler_dev_dsp::Audio_in::buf_info (audio_buf_info *p,
957957
{
958958
p->fragstotal = MAX_BLOCKS;
959959
p->fragsize = blockSize (rate, bits, channels);
960-
if (dev_)
960+
if (this && dev_)
961961
{
962962
p->fragments = Qisr2app_->query ();
963963
if (pHdr_ != NULL)

winsup/cygwin/pinfo.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags)
529529
bool __reg1
530530
_pinfo::exists ()
531531
{
532-
return process_state && !(process_state & (PID_EXITED | PID_REAPED | PID_EXECED));
532+
return this && process_state && !(process_state & (PID_EXITED | PID_REAPED | PID_EXECED));
533533
}
534534

535535
bool
@@ -720,7 +720,7 @@ _pinfo::commune_request (__uint32_t code, ...)
720720
res.s = NULL;
721721
res.n = 0;
722722

723-
if (!pid)
723+
if (!this || !pid)
724724
{
725725
set_errno (ESRCH);
726726
goto err;
@@ -819,7 +819,7 @@ _pinfo::commune_request (__uint32_t code, ...)
819819
fhandler_pipe *
820820
_pinfo::pipe_fhandler (int64_t unique_id, size_t &n)
821821
{
822-
if (!pid)
822+
if (!this || !pid)
823823
return NULL;
824824
if (pid == myself->pid)
825825
return NULL;
@@ -832,7 +832,7 @@ char *
832832
_pinfo::fd (int fd, size_t &n)
833833
{
834834
char *s;
835-
if (!pid)
835+
if (!this || !pid)
836836
return NULL;
837837
if (pid != myself->pid)
838838
{
@@ -856,7 +856,7 @@ char *
856856
_pinfo::fds (size_t &n)
857857
{
858858
char *s;
859-
if (!pid)
859+
if (!this || !pid)
860860
return NULL;
861861
if (pid != myself->pid)
862862
{
@@ -884,7 +884,7 @@ char *
884884
_pinfo::root (size_t& n)
885885
{
886886
char *s;
887-
if (!pid)
887+
if (!this || !pid)
888888
return NULL;
889889
if (pid != myself->pid && !ISSTATE (this, PID_NOTCYGWIN))
890890
{
@@ -930,7 +930,7 @@ char *
930930
_pinfo::cwd (size_t& n)
931931
{
932932
char *s = NULL;
933-
if (!pid)
933+
if (!this || !pid)
934934
return NULL;
935935
if (ISSTATE (this, PID_NOTCYGWIN))
936936
{
@@ -976,7 +976,7 @@ char *
976976
_pinfo::cmdline (size_t& n)
977977
{
978978
char *s = NULL;
979-
if (!pid)
979+
if (!this || !pid)
980980
return NULL;
981981
if (ISSTATE (this, PID_NOTCYGWIN))
982982
{
@@ -1036,7 +1036,7 @@ char *
10361036
_pinfo::environ (size_t& n)
10371037
{
10381038
char **env = NULL;
1039-
if (!pid)
1039+
if (!this || !pid)
10401040
return NULL;
10411041
if (ISSTATE (this, PID_NOTCYGWIN))
10421042
{

winsup/cygwin/signal.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ _pinfo::kill (siginfo_t& si)
260260
}
261261
this_pid = pid;
262262
}
263-
else if (process_state == PID_EXITED)
263+
else if (this && process_state == PID_EXITED)
264264
{
265265
this_process_state = process_state;
266266
this_pid = pid;

0 commit comments

Comments
 (0)