fedora 23
integer weakness #1

2

Weakness Breakdown


Definition:

An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:

ElectricFence-2.2.2/efence.c

Context:

The highlighted line of code below is the trigger point of this particular Fedora 23 integer weakness.

 	/* of our call stack. */
	if (semDepth == 0) {
		/* Zero this before actually free'ing the semaphore. */
		semThread = (pthread_t) 0;
		if (sem_post(&EF_sem) < 0)
			EF_InternalError("Failed to post the semaphore.");
	}
#endif /* USE_SEMAPHORE */
}

/*
 * initialize sets up the memory allocation arena and the run-time
 * configuration information.
 */
static void
initialize(void)
{
	size_t	size = MEMORY_CREATION_SIZE;
	size_t	slack;
	char *	string;
	Slot *	slot;

	if ( EF_DISABLE_BANNER == -1 ) {
		if ( (string = getenv("EF_DISABLE_BANNER")) != 0 )
			EF_DISABLE_BANNER = atoi(string);
		else
			EF_DISABLE_BANNER = 0;
	}

	if ( EF_DISABLE_BANNER == 0 )
		EF_Print(version);

#ifdef USE_SEMAPHORE
	if (sem_init != NULL && !pthread_initialization && sem_init(&EF_sem, 0, 1) >= 0) {
		semEnabled = 1;
	}
#endif
	lock();

	/*
	 * Import the user's environment specification of the default
	 * alignment for malloc(). We want that alignment to be under
	 * user control, since smaller alignment lets us catch more bugs,
	 * however some software will break if malloc() returns a buffer
	 * that is not word-aligned.
	 *
	 * I would like
	 * alignment to be zero so that we could catch all one-byte
	 * overruns, however if malloc() is asked to allocate an odd-size
	 * buffer and returns an address that is not word-aligned, or whose 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.