aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-03 11:29:51 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-03 11:29:51 -0700
commit20cd14971fd5aeb5c731ef0e17b586c5a46b27f9 (patch)
tree07107dd7edf73be37a4c6cf62cdc4bf4c19d2589
parentcc14e2ad3a8764b3ee56fee0a7a71dc5be3de5ec (diff)
fix gethostbyname closure error
-rw-r--r--src/library.js38
-rwxr-xr-xtests/runner.py8
2 files changed, 24 insertions, 22 deletions
diff --git a/src/library.js b/src/library.js
index 7757bf75..72fb07e7 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6352,37 +6352,39 @@ LibraryManager.library = {
// name resolving clientside in a browser.
// we do the aliasing in 172.29.*.*, giving us 65536 possibilities
// note: lots of leaking here!
+ __hostent_struct_layout: Runtime.generateStructInfo([
+ ['i8*', 'h_name'],
+ ['i8**', 'h_aliases'],
+ ['i32', 'h_addrtype'],
+ ['i32', 'h_length'],
+ ['i8**', 'h_addr_list'],
+ ]),
+ gethostbyname__deps: ['__hostent_struct_layout'],
gethostbyname: function(name) {
name = Pointer_stringify(name);
- if (!_gethostbyname.hostent_layout) {
- _gethostbyname.hostent_layout = Runtime.generateStructInfo([
- ['i8*', 'h_name'],
- ['i8**', 'h_aliases'],
- ['i32', 'h_addrtype'],
- ['i32', 'h_length'],
- ['i8**', 'h_addr_list'],
- ]);
- _gethostbyname.table = {};
- _gethostbyname.id = 0;
- }
+ if (!_gethostbyname.id) {
+ _gethostbyname.id = 1;
+ _gethostbyname.table = {};
+ }
var id = _gethostbyname.id++;
assert(id < 65535);
+ var fakeAddr = 172 | (29 << 8) | ((id & 0xff) << 16) | ((id & 0xff00) << 24);
_gethostbyname.table[id] = name;
// generate hostent
- var ret = _malloc(_gethostbyname.hostent_layout.__size__);
+ var ret = _malloc(___hostent_struct_layout.__size__);
var nameBuf = _malloc(name.length+1);
writeStringToMemory(name, nameBuf);
- setValue(ret+_gethostbyname.hostent_layout.h_name, nameBuf, 'i8*');
+ setValue(ret+___hostent_struct_layout.h_name, nameBuf, 'i8*');
var aliasesBuf = _malloc(4);
setValue(aliasesBuf, 0, 'i8*');
- setValue(ret+_gethostbyname.hostent_layout.h_aliases, aliasesBuf, 'i8**');
- setValue(ret+_gethostbyname.hostent_layout.h_addrtype, {{{ cDefine("AF_INET") }}}, 'i32');
- setValue(ret+_gethostbyname.hostent_layout.h_length, 4, 'i32');
+ setValue(ret+___hostent_struct_layout.h_aliases, aliasesBuf, 'i8**');
+ setValue(ret+___hostent_struct_layout.h_addrtype, {{{ cDefine("AF_INET") }}}, 'i32');
+ setValue(ret+___hostent_struct_layout.h_length, 4, 'i32');
var addrListBuf = _malloc(12);
setValue(addrListBuf, addrListBuf+8, 'i32*');
setValue(addrListBuf+4, 0, 'i32*');
- setValue(addrListBuf+8, 172 | (29 << 8) | ((id & 0xff) << 16) | ((id & 0xff00) << 24), 'i32');
- setValue(ret+_gethostbyname.hostent_layout.h_addr_list, addrListBuf, 'i8**');
+ setValue(addrListBuf+8, fakeAddr, 'i32');
+ setValue(ret+___hostent_struct_layout.h_addr_list, addrListBuf, 'i8**');
return ret;
},
diff --git a/tests/runner.py b/tests/runner.py
index 41a62d37..37a8d597 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -5114,11 +5114,11 @@ def process(filename):
}
'''
self.do_run(src, '''www.cheezburger.com : 1 : 4
-* -84.29.0.0.
-fail.on.this.never.work : 1 : 4
* -84.29.1.0.
-localhost : 1 : 4
+fail.on.this.never.work : 1 : 4
* -84.29.2.0.
+localhost : 1 : 4
+* -84.29.3.0.
''')
def test_ctype(self):
@@ -8798,7 +8798,7 @@ elif 'browser' in str(sys.argv):
def test_zz_websockets_gethostbyname(self):
try:
with self.WebsockHarness(7000):
- self.btest('websockets_gethostbyname.c', expected='571')
+ self.btest('websockets_gethostbyname.c', expected='571', args=['-O2'])
finally:
self.clean_pids()