如何处理 GetDllDirectory 产生的模糊值?

发布于 2024-09-03 13:03:50 字数 710 浏览 4 评论 0原文

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所有深爱都是秘密 2024-09-10 13:03:50

没有解决这个问题。在进退两难的情况下,您应该假设 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文