kuno / GeoIP

GeoIP binding for nodejs(>=0.10) and iojs
GNU Lesser General Public License v2.1
414 stars 129 forks source link

Crash and burn when given an invalid .dat file #47

Closed DanH42 closed 11 years ago

DanH42 commented 11 years ago

I just spent half an hour trying to figure out what was wrong with the server I'd just moved an application to, when it turns out the only problem is that the GeoIP .dat I was pointing at wasn't what I thought it was. Rather than a helpful error telling me that the file couldn't be read properly, I was seeing this:

xd6:~$ node
> var geoip = require('geoip')
undefined
> var city = new geoip.City("/usr/share/GeoIP/GeoIP.dat"); // NOT GeoIPCity
*** glibc detected *** node: double free or corruption (!prev): 0x09aa8b60 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb745aee2]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0xb769e51f]
/home/xd6/node_modules/geoip/build/Release/geoip.node(_ZN5geoip4City3NewERKN2v89ArgumentsE+0x1d7)[0xb73c60e7]
node[0x830da2c]
[0xa150a236]
[0xa150f30f]
[0xb084e8e2]
[0xa150f3d9]
[0xa150a0aa]
node[0x83307ed]
======= Memory map: ========
08048000-08780000 r-xp 00000000 ca:01 6111761    /usr/bin/nodejs
08780000-08781000 r-xp 00737000 ca:01 6111761    /usr/bin/nodejs
08781000-0878b000 rwxp 00738000 ca:01 6111761    /usr/bin/nodejs
0878b000-08793000 rwxp 00000000 00:00 0 
09a7a000-09b8e000 rwxp 00000000 00:00 0          [heap]
82300000-82349000 rwxp 00000000 00:00 0 
84c00000-84c29000 rwxp 00000000 00:00 0 
87900000-87909000 rwxp 00000000 00:00 0 
87909000-8790a000 ---p 00000000 00:00 0 
8790a000-87933000 rwxp 00000000 00:00 0
87933000-87934000 ---p 00000000 00:00 0 
88ccc000-88ccd000 r-xp 00000000 00:00 0 
8a722000-8a740000 ---p 00000000 00:00 0 
8a740000-8a750000 rwxp 00000000 00:00 0 
8a750000-8a752000 ---p 00000000 00:00 0 
8f97c000-8f97d000 r-xp 00000000 00:00 0 
93600000-93700000 rwxp 00000000 00:00 0 
94d8b000-94d8c000 r-xp 00000000 00:00 0 
a1500000-a1509000 rwxp 00000000 00:00 0 
a1509000-a150a000 ---p 00000000 00:00 0 
a150a000-a156a000 rwxp 00000000 00:00 0 
a156a000-a156b000 ---p 00000000 00:00 0 
a40a9000-a40aa000 r-xp 00000000 00:00 0 
aab77000-aac77000 rwxp 00000000 00:00 0 
ab2a3000-ab2a4000 r-xp 00000000 00:00 0 
ac398000-ac399000 r-xp 00000000 00:00 0 
b0800000-b0809000 rwxp 00000000 00:00 0 
b0809000-b080a000 ---p 00000000 00:00 0 
b080a000-b08ff000 rwxp 00000000 00:00 0 
b08ff000-b0900000 ---p 00000000 00:00 0 
b1100000-b1121000 rwxp 00000000 00:00 0 
b3e00000-b3f00000 rwxp 00000000 00:00 0 
b6000000-b6700000 ---p 00000000 00:00 0 
b6700000-b6800000 rwxp 00000000 00:00 0 
b6800000-b6f00000 ---p 00000000 00:00 0 
b6f00000-b7000000 rwxp 00000000 00:00 0 
b70ff000-b7200000 rwxp 00000000 00:00 0 
b7200000-b7221000 rwxp 00000000 00:00 0 
b7221000-b7300000 ---p 00000000 00:00 0 
b738a000-b73ba000 r-xp 00000000 ca:01 6063879    /usr/lib/libGeoIP.so.1.4.8
b73ba000-b73bb000 r-xp 00030000 ca:01 6063879    /usr/lib/libGeoIP.so.1.4.8
b73bb000-b73bc000 rwxp 00031000 ca:01 6063879    /usr/lib/libGeoIP.so.1.4.8
b73bc000-b73cf000 r-xp 00000000 ca:01 3164473    /home/xd6/node_modules/geoip/build/Release/geoip.node
b73cf000-b73d0000 r-xp 00012000 ca:01 3164473    /home/xd6/node_modules/geoip/build/Release/geoip.node
b73d0000-b73d1000 rwxp 00013000 ca:01 3164473    /home/xd6/node_modules/geoip/build/Release/geoip.node
b73d1000-b73d2000 ---p 00000000 00:00 0 
b73d2000-b73e5000 rwxp 00000000 00:00 0 
b73e5000-b7588000 r-xp 00000000 ca:01 12469620   /lib/i386-linux-gnu/libc-2.15.so
b7588000-b7589000 ---p 001a3000 ca:01 12469620   /lib/i386-linux-gnu/libc-2.15.so
b7589000-b758b000 r-xp 001a3000 ca:01 12469620   /lib/i386-linux-gnu/libc-2.15.so
b758b000-b758c000 rwxp 001a5000 ca:01 12469620   /lib/i386-linux-gnu/libc-2.15.so
b758c000-b758f000 rwxp 00000000 00:00 0 
b758f000-b75a6000 r-xp 00000000 ca:01 12469629   /lib/i386-linux-gnu/libpthread-2.15.so
b75a6000-b75a7000 r-xp 00016000 ca:01 12469629   /lib/i386-linux-gnu/libpthread-2.15.so
b75a7000-b75a8000 rwxp 00017000 ca:01 12469629   /lib/i386-linux-gnu/libpthread-2.15.so
b75a8000-b75aa000 rwxp 00000000 00:00 0 
b75aa000-b75c6000 r-xp 00000000 ca:01 12468330   /lib/i386-linux-gnu/libgcc_s.so.1
b75c6000-b75c7000 r-xp 0001b000 ca:01 12468330   /lib/i386-linux-gnu/libgcc_s.so.1
b75c7000-b75c8000 rwxp 0001c000 ca:01 12468330   /lib/i386-linux-gnu/libgcc_s.so.1
b75c8000-b75f2000 r-xp 00000000 ca:01 12469631   /lib/i386-linux-gnu/libm-2.15.so
b75f2000-b75f3000 r-xp 00029000 ca:01 12469631   /lib/i386-linux-gnu/libm-2.15.so
b75f3000-b75f4000 rwxp 0002a000 ca:01 12469631   /lib/i386-linux-gnu/libm-2.15.so
b75f4000-b75f5000 rwxp 00000000 00:00 0 
b75f5000-b76cd000 r-xp 00000000 ca:01 6129347    /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
b76cd000-b76ce000 ---p 000d8000 ca:01 6129347    /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
b76ce000-b76d2000 r-xp 000d8000 ca:01 6129347    /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
b76d2000-b76d3000 rwxp 000dc000 ca:01 6129347    /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
b76d3000-b76da000 rwxp 00000000 00:00 0 
b76da000-b76e1000 r-xp 00000000 ca:01 12469627   /lib/i386-linux-gnu/librt-2.15.so
b76e1000-b76e2000 r-xp 00006000 ca:01 12469627   /lib/i386-linux-gnu/librt-2.15.so
b76e2000-b76e3000 rwxp 00007000 ca:01 12469627   /lib/i386-linux-gnu/librt-2.15.so
b76e3000-b76e6000 r-xp 00000000 ca:01 12469635   /lib/i386-linux-gnu/libdl-2.15.so
b76e6000-b76e7000 r-xp 00002000 ca:01 12469635   /lib/i386-linux-gnu/libdl-2.15.so
b76e7000-b76e8000 rwxp 00003000 ca:01 12469635   /lib/i386-linux-gnu/libdl-2.15.so
b76ec000-b76f1000 rwxp 00000000 00:00 0 
b76f1000-b76f2000 r-xp 00000000 00:00 0          [vdso]
b76f2000-b7712000 r-xp 00000000 ca:01 12469632   /lib/i386-linux-gnu/ld-2.15.so
b7712000-b7713000 r-xp 0001f000 ca:01 12469632   /lib/i386-linux-gnu/ld-2.15.so
b7713000-b7714000 rwxp 00020000 ca:01 12469632   /lib/i386-linux-gnu/ld-2.15.so
b94db000-b98db000 rwxp 00000000 00:00 0 
bcf00000-bcf39000 rwxp 00000000 00:00 0 
bfb51000-bfb72000 rwxp 00000000 00:00 0          [stack]
Aborted
xd6:~$

Could we maybe perform a quick check to ensure that the data being read in is valid?

kuno commented 11 years ago

thx, let me take a look...

kuno commented 11 years ago

Fixed in the 0.8+.

Closing.