简体   繁体   中英

How might one cope with the ambiguous value produced by GetDllDirectory?

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?

PS 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM