Skip to content

src,deps: wrap library name with TEXT()#226

Closed
zcbenz wants to merge 1 commit into
nodejs:v1.xfrom
zcbenz:unicode-dlopen
Closed

src,deps: wrap library name with TEXT()#226
zcbenz wants to merge 1 commit into
nodejs:v1.xfrom
zcbenz:unicode-dlopen

Conversation

@zcbenz

@zcbenz zcbenz commented Dec 31, 2014

Copy link
Copy Markdown
Contributor

On Windows when compiling with unicode support, "LoadLibrary" will become "LoadLibraryW" and feeding it with an ANSCII string will cause crash in runtime.

Using TEXT() macro can make the code work no matter whether the unicode support is on.

@bnoordhuis

Copy link
Copy Markdown
Member

/cc @piscisaureus

@piscisaureus

Copy link
Copy Markdown
Contributor

-1
Just use the A or W version explicitly

@zcbenz

zcbenz commented Dec 31, 2014

Copy link
Copy Markdown
Contributor Author

@piscisaureus Will you accept the commit if I change it to use LoadLibraryA?

And FYI, in V8 and OpenSSL they chose to use TEXT() macro instead of A or W version of API, I'm not quite sure about the reason but using TEXT() seems more consistent:
https://github.com/iojs/io.js/search?utf8=✓&q=LoadLibrary

@piscisaureus

Copy link
Copy Markdown
Contributor

@piscisaureus Will you accept the commit if I change it to use LoadLibraryA?

I'll accept it if you change it to use LoadLibraryW to make it look like this:

hnd_advapi32 = LoadLibraryW(L"advapi32.dll");

The reason is that LoadLibraryA just converts the name from the "active ansi character set" to utf16 and then calls LoadLibraryW internally. The TEXT() macro is a relic from times where people were targeting Windows NT (with unicode support) and 95/98 (no unicode support) at the same time.

On Windows when compiling with unicode support, "LoadLibrary" will
become "LoadLibraryW" and feeding it with an ANSCII string will cause
crash in runtime.
@zcbenz

zcbenz commented Jan 7, 2015

Copy link
Copy Markdown
Contributor Author

Sounds quite reasonable to me, I have updated the patch to use LoadLibraryW.

piscisaureus pushed a commit that referenced this pull request Jan 7, 2015
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: #226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
@piscisaureus

Copy link
Copy Markdown
Contributor

Thanks! Landed in 604b876.

@piscisaureus

Copy link
Copy Markdown
Contributor

@zcbenz BTW you may want to upstream the patch to c-ares too. Chances are that your change gets reverted when someone upgrades c-ares.

@zcbenz

zcbenz commented Jan 8, 2015

Copy link
Copy Markdown
Contributor Author

I have created c-ares/c-ares#25 for the upstream c-ares.

bnoordhuis pushed a commit to bnoordhuis/io.js that referenced this pull request May 11, 2015
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: nodejs#226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
bnoordhuis pushed a commit to bnoordhuis/io.js that referenced this pull request May 11, 2015
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: nodejs#226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
bnoordhuis pushed a commit to bnoordhuis/io.js that referenced this pull request May 12, 2015
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: nodejs#226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request May 19, 2015
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: nodejs#226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
indutny pushed a commit to indutny/io.js that referenced this pull request Feb 4, 2016
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: nodejs#226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
indutny pushed a commit that referenced this pull request Feb 8, 2016
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: #226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
rvagg pushed a commit that referenced this pull request Feb 9, 2016
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: #226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
rvagg pushed a commit that referenced this pull request Feb 9, 2016
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: #226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
@MylesBorins

Copy link
Copy Markdown
Contributor

This landed upstream in cares... although I'm not sure we are backporting changes to LTS. Should this be backported?

@jasnell

jasnell commented Mar 11, 2016

Copy link
Copy Markdown
Member

Likely safe. SGTM /cc @nodejs/lts

@rvagg

rvagg commented Mar 14, 2016

Copy link
Copy Markdown
Member

@thealphanerd probably not needed, check the diff against v4. This one's a floating patch that kept coming on top of c-ares changes. git log | grep 'src,deps: replace LoadLibrary by LoadLibraryW' (I got confused by this stage while backporting as well).

scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
On Windows, when compiling with `UNICODE` defined, `LoadLibrary` becomes
`LoadLibraryW`. When an ASCII string is passed to that function it
crashes.

PR-URL: nodejs#226
Reviewed-By: Bert Belder <bertbelder@gmail.com>
isaacs added a commit to npm/node that referenced this pull request Aug 6, 2019
BUGFIXES

* [`27cccfbda`](npm/cli@27cccfb)
  [nodejs#223](npm/cli#223) vulns → vulnerabilities in
  npm audit output ([@sapegin](https://github.com/sapegin))
* [`d5e865eb7`](npm/cli@d5e865e)
  [nodejs#222](npm/cli#222)
  [nodejs#226](npm/cli#226) install, doctor: don't crash
  if registry unset ([@dmitrydvorkin](https://github.com/dmitrydvorkin),
  [@isaacs](https://github.com/isaacs))
* [`5b3890226`](npm/cli@5b38902)
  [nodejs#227](npm/cli#227)
  [npm.community#9167](https://npm.community/t/npm-err-cb-never-called-permission-denied/9167/5)
  Handle unhandledRejections, tell user what to do when encountering an
  `EACCES` error in the cache.  ([@isaacs](https://github.com/isaacs))

DEPENDENCIES

* [`77516df6e`](npm/cli@77516df)
  `licensee@7.0.3` ([@isaacs](https://github.com/isaacs))
* [`ceb993590`](npm/cli@ceb9935)
  `query-string@6.8.2` ([@isaacs](https://github.com/isaacs))
* [`4050b9189`](npm/cli@4050b91)
  `hosted-git-info@2.8.2`
    * [nodejs#46](npm/hosted-git-info#46)
      [nodejs#43](npm/hosted-git-info#43)
      [nodejs#47](npm/hosted-git-info#47)
      [nodejs#44](npm/hosted-git-info#44) Add support for
      GitLab subgroups ([@mterrel](https://github.com/mterrel),
      [@isaacs](https://github.com/isaacs),
      [@ybiquitous](https://github.com/ybiquitous))
    * [`3b1d629`](npm/hosted-git-info@3b1d629)
      [nodejs#48](npm/hosted-git-info#48) fix http
      protocol using sshurl by default
      ([@fengmk2](https://github.com/fengmk2))
    * [`5d4a8d7`](npm/hosted-git-info@5d4a8d7)
      ignore noCommittish on tarball url generation
      ([@isaacs](https://github.com/isaacs))
    * [`1692435`](npm/hosted-git-info@1692435)
      use gist tarball url that works for anonymous gists
      ([@isaacs](https://github.com/isaacs))
    * [`d5cf830`](npm/hosted-git-info@d5cf830)
      Do not allow invalid gist urls ([@isaacs](https://github.com/isaacs))
    * [`e518222`](npm/hosted-git-info@e518222)
      Use LRU cache to prevent unbounded memory consumption
      ([@iarna](https://github.com/iarna))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants