[fdordbms] UnitTest segmentation fault

Mateusz Loskot mateusz at loskot.net
Sat Oct 7 06:25:14 EDT 2006


I'd like to report some problems with UnitTest program for FDO RDBMS.

First, when I try to run it, I'm getting segmentation fault.
I tested using my init files with following definitions:


Note, empty password= option or no password option is intentional,
because my 'root' user doesn't use password on my machine.
Now, I run tests:

./UnitTestMySql initfiletest=mysql-mloskot-init.txt
22MySqlFdoCapabilityTest.datastore (Sat Oct  7 11:27:26 2006):
Segmentation fault

After short investigation, I found where is the problem.
This particular segmentation fault issue occurs in file
in function void FdoCapabilityTest::datastore(),
near line 271:

const wchar_t *password = dictionary->GetProperty(L"Password");
mbstowcs(temp, UnitTestUtil::GetEnviron("password"), sizeof(temp));

For my custom test init file, where I try to use empty password,
the UnitTestUtil::GetEnviron("password") returns NULL.
NULL passed to mbstowcs causes segmentation fault.

NOTE: Yes, I might have used empty password incorrectly, but it doesn't
change the situation that calling mbstowcs() with NULL pointers
makes program ill-formed.

Here are a few dangerous situations I see in UnitTest programs:

1. Values returned from getenv() is not checked for NULL before passing
it to <string.h> or <stdlib.h> functions.
This problem occurs in:

ConnectionUtil::GetEnviron(const char *name, const char *suffix)

2. char* pointers returned from other functions and passed to mbstowcs()
are not checked for NULL

3. I added my own test for NULL pointer to GetEnviron() function and for
'password' parameter only, it prints huge number of places where this
variable is used:


Every message GetEnviron("password") == NULL is a potential
segmentation fault.

The C language standard ( The mbstowcs function, 7.1.4 Use of
library functions) says:

"1  (...) If an argument to a function has an invalid value (such as a
value outside the domain of the function, or a pointer outside the
address space of the program, or a null pointer, (...) ,
the behavior is undefined (...)"

In CRT from Visual C++, Microsoft provides it's own extension to handle
such undefined behavior cases more gracefully and the invalid parameter
handler is invoked. By default, the handler shouts Access Violation (in
release). In debug, most of CRT functions catch assertion for such
cases, during parameter validation.

Do you use custom "Invalid Parameter Handler Routine" on Windows to
catch these issues, so you have not noticed any problems with NULL
string passed into mbstowcs() calls?

I understand that may be I should use non-empty password=xxxx option,
but UnitTest program doesn't warn about it.
Here is another option I've tried to use to pass empty password:


and this time, ./UnitTestMySql program does not print my custom warnings
about null password variable, but prints one about missing 'schematype':

18MySqlFdoSchemaTest.OverrideTablesWithOddAsciiChars (Sat Oct  7
12:14:42 2006):
 - UnitTestUtil::InfoUtilConnection->GetEnviron("schematype") == NULL

and crashes a few messages later:

18MySqlFdoInsertTest.insertEmptyProps (Sat Oct  7 12:14:44 2006):
Segmentation fault

Here is complete log

Inspite of my experiments with empty/non-empty passwords,
I think these unit tests behave in some instable way.
I don't know which options are mandatory which are not, in the
initfiletest, so I just tried and discovered these problems.

Mateusz Loskot

More information about the Fdo-internals mailing list