如何处理 GetDllDirectory 产生的模糊值?
GetDllDirectory
产生一个不明确的值。当此调用生成的字符串为空时,则意味着以下情况之一:
- 没有人调用
SetDllDirectory
- 有人将
NULL
传递给SetDllDirectory
- 有人传递了一个空string to
SetDllDirectory
前两种情况对于我的目的来说是等效的,但第三种情况是一个问题。如果我想编写保存/恢复代码(调用 GetDllDirectory
保存“旧”值,SetDllDirectory
临时设置“新”值,稍后调用 SetDllDirectory
再次恢复“旧”值),我冒着扭转其他程序员意图的风险。
如果其他程序员希望当前工作目录处于 DLL 搜索顺序中(换句话说,前两个项目符号之一为 true),并且我将空字符串传递给 SetDllDirectory
,我将将当前工作目录从 DLL 搜索顺序中取出,从而扭转了其他程序员的意图。
谁能提出一种消除或解决这种歧义的方法?
PS 我知道 DLL 搜索顺序中的当前工作目录可能会被解释为安全漏洞。然而,这是默认行为,我的代码无法撤消它;我的代码需要与所有潜在调用者的期望兼容,其中许多调用者又大又旧,超出了我的控制范围。
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
toSetDllDirectory
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有解决这个问题。在进退两难的情况下,您应该假设 NULL 已被传递。已经有一种方法可以通过注册表设置启用安全搜索。
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.