Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using id() to generate a 32-bit integer fails in 64-bit environment #14

Closed
GoogleCodeExporter opened this issue Mar 27, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

with a 64-bit build of python, id() results often exceed 2**32, which causes 
structure.pack to be unhappy.

Found this in the srvsvcserver code, but maybe it's elsewhere.. Here's what I 
did to fix (not bulletproof, but probably safe?):

Index: impacket/dcerpc/srvsvcserver.py
===================================================================
--- impacket/dcerpc/srvsvcserver.py (revision 714)
+++ impacket/dcerpc/srvsvcserver.py (working copy)
@@ -212,6 +212,9 @@
 import ConfigParser
 import struct

+def _get_id(o):
+  return id(o) & 0xffffffff
+
 class SRVSVCServer(DCERPCServer):
     def __init__(self):
         DCERPCServer.__init__(self)
@@ -243,9 +246,9 @@
        answer = srvsvc.SRVSVCSwitchpShareInfo2()
        answer['Level']      = 1
        answer['InfoStruct'] = srvsvc.SRVSVCShareInfo1()
-       answer['InfoStruct']['pNetName'] = id(share)
+       answer['InfoStruct']['pNetName'] = _get_id(share)
        answer['InfoStruct']['Type']     = int(share['share type'])
-       answer['InfoStruct']['pRemark']  = id(share)+1
+       answer['InfoStruct']['pRemark']  = _get_id(share)+1
        answer = str(answer)
        netName = srvsvc.NDRString()
        remark  = srvsvc.NDRString()
@@ -276,9 +279,9 @@
        answer = str(shareEnum) 
        for i in self.__shares:
           shareInfo = srvsvc.SRVSVCShareInfo1()
-          shareInfo['pNetName'] = id(i)
+          shareInfo['pNetName'] = _get_id(i)
           shareInfo['Type']     = int(self.__shares[i]['share type'])
-          shareInfo['pRemark']  = id(i)+1
+          shareInfo['pRemark']  = _get_id(i)+1
           answer += str(shareInfo)

        for i in self.__shares:

Original issue reported on code.google.com by bryanbu...@gmail.com on 10 Sep 2012 at 5:14

@GoogleCodeExporter
Copy link
Author

Wow.. nice catch Bryan.. Can you send me an output of the error you receive?


Original comment by bet...@gmail.com on 10 Sep 2012 at 5:26

  • Changed state: Accepted
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

caught exception: ("'L' format requires 0 <= number <= 4294967295", "When 
packing field 'pNetName | <L | 4410144592' in 
impacket.dcerpc.srvsvc.SRVSVCShareInfo1")

Original comment by bryanbu...@gmail.com on 10 Sep 2012 at 5:28

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

here's a random test in my environment:

In [1]: x = id('test')

In [2]: x
Out[2]: 4341761680

In [3]: x > 2**32
Out[3]: True

In [4]: x - 2**32
Out[4]: 46794384

In [5]: import struct

In [6]: struct.pack('>L', x)
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-6-80b596231688> in <module>()
----> 1 struct.pack('>L', x)

error: 'L' format requires 0 <= number <= 4294967295

Original comment by bryanbu...@gmail.com on 10 Sep 2012 at 5:29

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Great...

Yep.. your fix indeed solves the problem.. but only if the definition of the 
structure field is '<L' (otherwise the mask should be changed).. stick to that 
fix.. and let me review the other parts of the library when id() is used and 
see if I can come up with something more general, that can check the 
structure's definition as well.

We had a similar issue in the past in structure (it uses id() for some stuff 
too..)...

graciass!
bto

Original comment by bet...@gmail.com on 10 Sep 2012 at 5:33

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Okey.. 

There weren't many other instances of the same problem.. (just a few in 
svcctl). Fixed in http://code.google.com/p/impacket/source/detail?r=715

Let me know if it works...

thanks bryan!

Original comment by bet...@gmail.com on 10 Sep 2012 at 7:41

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant