Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Bug of the Month – February 2011

Matt Schuetze1 Absent Member.
Absent Member.
0 0 761

This month’s case looks like a ghastly oversight in BoundsChecker, at least when first presented to our Customer Care and Engineering teams. The alleged bug appears to be that BoundsChecker is yielding a false negative for an uninitialized memory read. This is supposed to the ultimate BoundsChecker forte, detecting where memory misuse could lead to catastrophic process or data results. So let’s look at the boiled down code sample that shows the error:

 

 
 1| #include "stdafx.h"
 2|   
 3| int _tmain(int argc, _TCHAR* argv[])
 4| {
 5|   char v[10];
 6|   char w[10];
 7|   v[1] = w[1];  /*Uninitialized Memory Read: Pointer 0x001AFA91 (1) refers to an
 8|             uninitialized local variable w 0x001AFA90 (10) in function wmain.*/
 9|  
10|   wchar_t x[10];
11|   wchar_t y[10];
12|   x[1]=y[1];   /*Uninitialized Memory Read: Pointer 0x001AFA72 (2) refers to an
13|             uninitialized local variable y 0x001AFA70 (20) in function wmain.*/
14|  
15|   return 0;
16| }
 
 

The bug report stated that BoundsChecker only raised an Uninitialized Read Pointer on the second instance, namely the assignment on line 12. Why was it missing essentially the same code with the assignment on line 7? The answer lies in BoundsChecker’s use of the Fill on Allocation option in Memory Tracking. By default, Fill on Allocation is set to a two byte allocation pattern for guard bytes. Since the array of wchar_t’s contains two byte elements, BoundsChecker catches this out-of-the-box. To also have it catch the assignment for the char one byte elements, you must switch the option in Memory Tracking so Fill on Allocation uses one byte guard bytes. Doing this catches both line 7 and line 12, as the comments in source depict. This was a bit of head scratcher at first blush, but in retrospect makes tons of sense.

 

As more new C++ code moves to Unicode, use of bare chars falls away some. But because legacy code often still contains them, and because byte arrays will never go out of style, be wary of this potential for missed events against single byte operations. Why don’t we make guard bytes one byte by default to catch this out of the box? Single byte matching raises the odds that properly initialized memory may match the one byte guard pattern, leading to extra false positive noise. Some users in fact select four byte guards to further reduce odds of matching on a purposefully initialized object. This may miss smaller objects, but all the bigger, nastier ones remain detected.

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.