views:

46

answers:

1

GetDllDirectory produces an ambiguous value. When the string this call produces is empty, it means one of the following:

  • nobody has called SetDllDirectory
  • somebody passed NULL to SetDllDirectory
  • somebody passed an empty string to SetDllDirectory

The first two cases are equivalent for my purposes, but the third case is a problem. If I want to write save/restore code (call GetDllDirectory to save the "old" value, SetDllDirectory to set a "new" value temporarily, and later SetDllDirectory again to restore the "old" value), I run the risk of reversing some other programmer's intent.

If the other programmer intended for the current working directory to be in the DLL search order (in other words, one of the first two bullets is true), and I pass an empty string to SetDllDirectory, I will be taking the current working directory out of the DLL search order, reversing the other programmer's intent.

Can anyone suggest an approach to eliminate or work around this ambiguity?

P.S. I know having the current working directory in the DLL search order could be interpreted as a security hole. Nevertheless, it is the default behavior, and my code is not in a position to undo that; my code needs to be compatible with the expectations of all potential callers, many of which are large and old and beyond my control.

A: 

No fix for this. Between a rock and a hard place, you ought to assume that NULL was passed. There is already a way to enable safe searching with a registry setting.

Hans Passant
This would be as I expected. On the other hand, it's difficult to know how long to wait for someone to post a bright idea... :-)
Integer Poet
@Integer: long enough?
Hans Passant