Skip to content

Commit e13663d

Browse files
committed
src: network interface names are UTF-8 encoded
Fixes a bug that was introduced in commit f674b09 when v8::String::New() calls were replaced with calls to one-byte, two-byte and UTF-8 versions. It turns out that for network interface names, using a one-byte encoding can produce the wrong results on Windows. Use UTF-8 instead. Libuv on Windows correctly encodes non-ASCII characters in the interface name as UTF-8. On Unices however, the interface name is just a binary string with no particular encoding; that's why on UNIX platforms, we keep interpreting it as a one-byte string. Fixes nodejs/node-v0.x-archive#8633. PR-URL: node-forward/node#44 Reviewed-By: Bert Belder <bertbelder@gmail.com>
1 parent 7ab73ff commit e13663d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_os.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,17 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
231231
}
232232

233233
for (i = 0; i < count; i++) {
234-
name = OneByteString(env->isolate(), interfaces[i].name);
234+
const char* const raw_name = interfaces[i].name;
235+
236+
// On Windows, the interface name is the UTF8-encoded friendly name and may
237+
// contain non-ASCII characters. On UNIX, it's just a binary string with
238+
// no particular encoding but we treat it as a one-byte Latin-1 string.
239+
#ifdef _WIN32
240+
name = String::NewFromUtf8(env->isolate(), raw_name);
241+
#else
242+
name = OneByteString(env->isolate(), raw_name);
243+
#endif
244+
235245
if (ret->Has(name)) {
236246
ifarr = Local<Array>::Cast(ret->Get(name));
237247
} else {

0 commit comments

Comments
 (0)