Skip to content

NdrCString packing is broken #84

@Couskito

Description

@Couskito

Hi!

Thanks for the awesome library, I really like it!

While testing some RPC calls i noticed that the marshalling of C strings using NdrCString.pack() seemed to break for some reason (I can only assume this is an artifact left from the Python 2 transition).

Here is a simple program that should trigger the bug (at least it did on my setup using Python 3.9.13 and Windows 11) :

from windows.rpc import ndr

print(ndr.NdrCString.pack("Hello\x00"))

This yields the following stack trace :

PS C:\Users\cousky\Desktop\testdir> python .\test.py
Traceback (most recent call last):
  File "C:\Users\cousky\Desktop\testdir\test.py", line 3, in <module>
    a = ndr.NdrCString.pack("Hello\x00")
  File "C:\Users\cousky\AppData\Local\Programs\Python\Python39\lib\site-packages\windows\rpc\ndr.py", line 195, in pack
    result += data
TypeError: can't concat str to bytes

After having a quick look at windows\rpc\ndr.py it seems that encoding data to bytes by replacing result += data with result += data.encode() on line 195 fixes the issue, I can open a PR with the change for you if you wish.

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions