andreiko / adns-python

Automatically exported from code.google.com/p/adns-python
0 stars 1 forks source link

non allocated memory freed #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Try this script:
#!/usr/bin/python

import sys
import adns

class DNS:
    def __init__(self, domain, ns1, ns1_ip, ns2, ns2_ip):
        soa1 = self.find_soa(domain, ns1_ip)
        if soa1 == False:
            raise NameError, "DNS_SOA_Query1"
        soa2 = self.find_soa(domain, ns2_ip)
        if soa2 == False:
            raise NameError("DNS_SOA_Query2")
        (ns_primary1,  email1, serial1, ref1, ret1, exp1, min1) = soa1
        (ns_primary2,  email2, serial2, ref2, ret2, exp2, min2) = soa2
        if ns_primary1 != ns_primary2 or email1 != email2 or serial1 != 
serial2 or ref1 != ref2 or exp1 != exp2 or min1 != min2:
            raise NameError, "DNS_SOA_Different: ns1 %s, ns2 %s, %s vs %s" % 
(ns1, ns2, ns_primary1, ns_primary2)
        if  ns1 != ns_primary1 and ns1 != ns_primary2 and ns2 != 
ns_primary1 and ns2 != ns_primary2:
            raise NameError, "DNS_SOA_PrimaryNS_Different: whois: (%s, %s) 
dns (%s, %s)" % (ns1, ns2, ns_primary1, ns_primary2)

    def find_soa(self, domain, ip):
        if ip == '':
            ip = "213.25.186.11"
        cfg = "clearnameservers\nnameserver %s\n" % ip
        s = adns.init(0, sys.stderr, cfg)
        status, cname, expires, answer = s.synchronous(domain, 
adns.rr.SOAraw)
        if len(answer):
            return answer[0]
        else:
            return False

    def fetch_ns_list(self, domain, ip):
        pass

DNS("dns.pl", "fsdf.pl", "1.1.1.1", "sdfd.pl", "2.2.2.2")

it fails:
(gdb) r
Starting program: /home/users/arekm/python-test/bin/python2.5 adns-check.py
*** glibc detected *** /home/users/arekm/python-test/bin/python2.5: 
munmap_chunk(): invalid pointer: 0x00002ba1ffa390d8 ***
======= Backtrace: =========
/lib64/libc.so.6[0x2ba2004c6cdd]
/home/users/arekm/python-test/lib/python2.5/site-packages/
adns.so[0x2ba204a2976a]
/home/users/arekm/python-test/bin/python2.5[0x4e48fc]
/home/users/arekm/python-test/bin/python2.5[0x48dc44]
/home/users/arekm/python-test/bin/python2.5[0x48da06]
/home/users/arekm/python-test/bin/
python2.5(PyEval_EvalFrameEx+0x5df3)[0x489faa]
/home/users/arekm/python-test/bin/
python2.5(PyEval_EvalCodeEx+0xd61)[0x48bcc4]
/home/users/arekm/python-test/bin/python2.5[0x4e739d]
/home/users/arekm/python-test/bin/python2.5(PyObject_Call+0x40)[0x41a74a]
/home/users/arekm/python-test/bin/python2.5[0x422bfe]
/home/users/arekm/python-test/bin/python2.5(PyObject_Call+0x40)[0x41a74a]
/home/users/arekm/python-test/bin/
python2.5(PyEval_CallObjectWithKeywords+0x11c)[0x48d1c6]
/home/users/arekm/python-test/bin/python2.5(PyInstance_New+0x1b3)[0x41d868]
/home/users/arekm/python-test/bin/python2.5(PyObject_Call+0x40)[0x41a74a]
/home/users/arekm/python-test/bin/python2.5[0x48e16e]
/home/users/arekm/python-test/bin/python2.5[0x48da1f]
/home/users/arekm/python-test/bin/
python2.5(PyEval_EvalFrameEx+0x5df3)[0x489faa]
/home/users/arekm/python-test/bin/
python2.5(PyEval_EvalCodeEx+0xd61)[0x48bcc4]
/home/users/arekm/python-test/bin/python2.5(PyEval_EvalCode+0x57)[0x484199]
/home/users/arekm/python-test/bin/python2.5[0x4b3ea1]
/home/users/arekm/python-test/bin/python2.5(PyRun_FileExFlags+0xb9)[0x4b3e2b]
/home/users/arekm/python-test/bin/
python2.5(PyRun_SimpleFileExFlags+0x1f0)[0x4b2d90]
/home/users/arekm/python-test/bin/
python2.5(PyRun_AnyFileExFlags+0x76)[0x4b2682]
/home/users/arekm/python-test/bin/python2.5(Py_Main+0x897)[0x41243c]
/home/users/arekm/python-test/bin/python2.5(main+0x1b)[0x411703]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x2ba200478af4]
/home/users/arekm/python-test/bin/python2.5[0x411659]
======= Memory map: ========
00400000-00539000 r-xp 00000000 08:03 1044358336                         /
home/users/arekm/python-test/bin/python2.5
00738000-00770000 rw-p 00138000 08:03 1044358336                         /
home/users/arekm/python-test/bin/python2.5
00770000-00801000 rw-p 00770000 00:00 0                                  
[heap]
2ba1ff99a000-2ba1ff9b4000 r-xp 00000000 08:01 20994846                   /
lib64/ld-2.5.so
2ba1ff9b4000-2ba1ff9b5000 rw-p 2ba1ff9b4000 00:00 0
2ba1ff9de000-2ba1ffa61000 rw-p 2ba1ff9de000 00:00 0
2ba1ffbb4000-2ba1ffbb6000 rw-p 0001a000 08:01 20994846                   /
lib64/ld-2.5.so
2ba1ffbb6000-2ba1ffbcc000 r-xp 00000000 08:01 20972644                   /
lib64/libpthread-2.5.so
2ba1ffbcc000-2ba1ffdcb000 ---p 00016000 08:01 20972644                   /
lib64/libpthread-2.5.so
2ba1ffdcb000-2ba1ffdcd000 rw-p 00015000 08:01 20972644                   /
lib64/libpthread-2.5.so
2ba1ffdcd000-2ba1ffdd1000 rw-p 2ba1ffdcd000 00:00 0
2ba1ffdd1000-2ba1ffdd3000 r-xp 00000000 08:01 21016208                   /
lib64/libdl-2.5.so
2ba1ffdd3000-2ba1fffd3000 ---p 00002000 08:01 21016208                   /
lib64/libdl-2.5.so
2ba1fffd3000-2ba1fffd5000 rw-p 00002000 08:01 21016208                   /
lib64/libdl-2.5.so
2ba1fffd5000-2ba1fffd7000 r-xp 00000000 08:01 20972652                   /
lib64/libutil-2.5.so
2ba1fffd7000-2ba2001d6000 ---p 00002000 08:01 20972652                   /
lib64/libutil-2.5.so
2ba2001d6000-2ba2001d8000 rw-p 00001000 08:01 20972652                   /
lib64/libutil-2.5.so
2ba2001d8000-2ba2001d9000 rw-p 2ba2001d8000 00:00 0
2ba2001d9000-2ba200259000 r-xp 00000000 08:01 21016210                   /
lib64/libm-2.5.so
2ba200259000-2ba200459000 ---p 00080000 08:01 21016210                   /
lib64/libm-2.5.so
2ba200459000-2ba20045b000 rw-p 00080000 08:01 21016210                   /
lib64/libm-2.5.so
2ba20045b000-2ba20058f000 r-xp 00000000 08:01 21016203                   /
lib64/libc-2.5.so
2ba20058f000-2ba20078f000 ---p 00134000 08:01 21016203                   /
lib64/libc-2.5.so
2ba20078f000-2ba200792000 r--p 00134000 08:01 21016203                   /
lib64/libc-2.5.so
2ba200792000-2ba200794000 rw-p 00137000 08:01 2
Program received signal SIGABRT, Aborted.
0x00002ba20048b145 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00002ba20048b145 in raise () from /lib64/libc.so.6
#1  0x00002ba20048c4ce in abort () from /lib64/libc.so.6
#2  0x00002ba2004c1b36 in ?? () from /lib64/libc.so.6
#3  0x00002ba2004c6cdd in ?? () from /lib64/libc.so.6
#4  0x00002ba204a2976a in ADNS_State_dealloc (self=0x2ba1ffa390d8) at 
adnsmodule.c:722
#5  0x00000000004e48fc in frame_dealloc (f=0x7e54d0) at Objects/
frameobject.c:416
#6  0x000000000048dc44 in fast_function (func=0x2ba1ffa56320, 
pp_stack=0x7fffff8a8618, n=3, na=3, nk=0) at Python/ceval.c:3654
#7  0x000000000048da06 in call_function (pp_stack=0x7fffff8a8618, oparg=2) 
at Python/ceval.c:3587
#8  0x0000000000489faa in PyEval_EvalFrameEx (f=0x7e9da0, throwflag=0) at 
Python/ceval.c:2269
#9  0x000000000048bcc4 in PyEval_EvalCodeEx (co=0x2ba1ffa47378, 
globals=0x79b360, locals=0x0, args=0x2ba1ffa5b1a0, argcount=6, kws=0x0, 
kwcount=0, defs=0x0,
    defcount=0, closure=0x0) at Python/ceval.c:2833
#10 0x00000000004e739d in function_call (func=0x2ba1ffa562a8, 
arg=0x2ba1ffa5b188, kw=0x0) at Objects/funcobject.c:517
#11 0x000000000041a74a in PyObject_Call (func=0x2ba1ffa562a8, 
arg=0x2ba1ffa5b188, kw=0x0) at Objects/abstract.c:1858
#12 0x0000000000422bfe in instancemethod_call (func=0x2ba1ffa562a8, 
arg=0x2ba1ffa5b188, kw=0x0) at Objects/classobject.c:2497
#13 0x000000000041a74a in PyObject_Call (func=0x2ba1ffa34190, 
arg=0x2ba1ffa06f50, kw=0x0) at Objects/abstract.c:1858
#14 0x000000000048d1c6 in PyEval_CallObjectWithKeywords 
(func=0x2ba1ffa34190, arg=0x2ba1ffa06f50, kw=0x0) at Python/ceval.c:3435
#15 0x000000000041d868 in PyInstance_New (klass=0x2ba1ffa06a70, 
arg=0x2ba1ffa06f50, kw=0x0) at Objects/classobject.c:560
#16 0x000000000041a74a in PyObject_Call (func=0x2ba1ffa06a70, 
arg=0x2ba1ffa06f50, kw=0x0) at Objects/abstract.c:1858
#17 0x000000000048e16e in do_call (func=0x2ba1ffa06a70, 
pp_stack=0x7fffff8a8f28, na=5, nk=0) at Python/ceval.c:3777
#18 0x000000000048da1f in call_function (pp_stack=0x7fffff8a8f28, oparg=5) 
at Python/ceval.c:3589
#19 0x0000000000489faa in PyEval_EvalFrameEx (f=0x7901b0, throwflag=0) at 
Python/ceval.c:2269
#20 0x000000000048bcc4 in PyEval_EvalCodeEx (co=0x2ba1ffa40e40, 
globals=0x79b360, locals=0x79b360, args=0x0, argcount=0, kws=0x0, 
kwcount=0, defs=0x0, defcount=0,
    closure=0x0) at Python/ceval.c:2833
#21 0x0000000000484199 in PyEval_EvalCode (co=0x2ba1ffa40e40, 
globals=0x79b360, locals=0x79b360) at Python/ceval.c:494
#22 0x00000000004b3ea1 in run_mod (mod=0x796520, filename=0x7fffff8aa740 
"adns-check.py", globals=0x79b360, locals=0x79b360, flags=0x7fffff8a9470, 
arena=0x784340)
    at Python/pythonrun.c:1264
#23 0x00000000004b3e2b in PyRun_FileExFlags (fp=0x778010, 
filename=0x7fffff8aa740 "adns-check.py", start=257, globals=0x79b360, 
locals=0x79b360, closeit=1,
    flags=0x7fffff8a9470) at Python/pythonrun.c:1250
#24 0x00000000004b2d90 in PyRun_SimpleFileExFlags (fp=0x778010, 
filename=0x7fffff8aa740 "adns-check.py", closeit=1, flags=0x7fffff8a9470) 
at Python/pythonrun.c:870
#25 0x00000000004b2682 in PyRun_AnyFileExFlags (fp=0x778010, 
filename=0x7fffff8aa740 "adns-check.py", closeit=1, flags=0x7fffff8a9470) 
at Python/pythonrun.c:689
#26 0x000000000041243c in Py_Main (argc=2, argv=0x7fffff8a95f8) at Modules/
main.c:523
#27 0x0000000000411703 in main (argc=2, argv=0x7fffff8a95f8) at ./Modules/
python.c:23
(gdb) quit
The program is running.  Exit anyway? (y or n) y
[arekm@arm ~/dns-verify]$ ef  ~/python-test/bin/python2.5 adns-check.py

  Electric Fence 2.2.0 Copyright (C) 1987-1999 Bruce Perens 
<bruce@perens.com>

ElectricFence Aborting: free(2b0a1a7ab0d8): address not from malloc().
Illegal instruction

segfaults in PyMem_DEL(self); in ADNS_State_dealloc()

Linux 2.6, glibc 2.5, python 2.5, adns 1.4, python-adns 1.2.0

Original issue reported on code.google.com by ar...@pld-linux.org on 8 Jan 2007 at 11:30

GoogleCodeExporter commented 9 years ago
The fix seems to be just:

diff -urN adns-python-1.2.0.org/adnsmodule.c adns-python-1.2.0/adnsmodule.c
--- adns-python-1.2.0.org/adnsmodule.c  2006-12-31 18:25:29.000000000 +0100
+++ adns-python-1.2.0/adnsmodule.c      2007-01-08 13:18:16.623624500 +0100
@@ -719,7 +719,7 @@
        adns_finish(self->state);
        Py_END_ALLOW_THREADS;
        Py_INCREF(Py_None);
-       PyMem_DEL(self);
+       PyObject_Free(self);
 }

 static char ADNS_Statetype__doc__[] =

More info at http://docs.python.org/whatsnew/ports.html, obmalloc part.

Original comment by ar...@pld-linux.org on 8 Jan 2007 at 12:19

GoogleCodeExporter commented 9 years ago
adns-python was originally written for Python-1.5. There are a number of Python 
API
updates that I need to do to make it truly compatible with Python-2.5. I am 
somewhat
surprised that PyMem_DEL is in there, though.

Original comment by farcep...@gmail.com on 8 Jan 2007 at 2:50

GoogleCodeExporter commented 9 years ago
Should be fixed shortly

Original comment by farcep...@gmail.com on 27 Jan 2007 at 7:05

GoogleCodeExporter commented 9 years ago
Fixed in r19

Original comment by farcep...@gmail.com on 27 Jan 2007 at 7:15