0

I'm trying to determine if a particular given C language source code run on Unison OS that I have could conceivably lead to a crash, and through what vectors. There are sections of the code that will on occasion attempt to dereference null pointers, access, but not write to, array indices out of bounds, and use possibly uninitialized variables.

The behavior is undefined and thus unpredictable in C, but according to other discussions I've read, the operating system and/or CPU will have a default behavior in these kinds of situations.

I don't own the code in question and I'm not trying to fix it. I just want to understand on a high level if there's a reasonable possibility of any of these (and which) leading to the program crashing.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
jaredad7
  • 304
  • 1
  • 2
  • 11

1 Answers1

1

I'll try to address each of your scenarios in general; I'm not an expert on Unison OS.

attempt to dereference null pointers

If the program dereferences a NULL pointer, the process should receive a SIGSEGV.

access, but not write to, array indices out of bounds

This depends on if the resulting addresses is readable by the process. As long as the resulting address is "valid" for reading, an attempt to read the value will fetch the appropriate number of bytes at the given address. If it goes "far enough" off the end of the array, to the point where the addresses are no longer valid, then the process should receive a SIGSEGV.

use possibly uninitialized variables

Reading bytes from memory returns the values last stored in those bytes. If your program has a stack-allocated variable that isn't initialized, then tries to read that variable, it'll get whatever was last written to those bytes.

Andy Dalton
  • 13,654
  • 1
  • 25
  • 45