diff options
author | nulano <nulano@nulano.eu> | 2020-12-25 18:11:34 +0100 |
---|---|---|
committer | nulano <nulano@nulano.eu> | 2020-12-25 18:11:34 +0100 |
commit | 6ce024094a186903a013a95329da471b6980c32a (patch) | |
tree | 9e7775374412158557460b564158218fed6ed986 | |
parent | backport e070d661: implement winreg reflection on win64 (diff) | |
download | pypy-6ce024094a186903a013a95329da471b6980c32a.tar.gz pypy-6ce024094a186903a013a95329da471b6980c32a.tar.bz2 pypy-6ce024094a186903a013a95329da471b6980c32a.zip |
backport d5d9fb27, fb5cddf8: bpo-21151, preserve None passed as REG_BINARY instead of crashing or changing it to an empty string
-rw-r--r-- | pypy/module/_winreg/interp_winreg.py | 11 | ||||
-rw-r--r-- | pypy/module/_winreg/test/test_winreg.py | 1 |
2 files changed, 8 insertions, 4 deletions
diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py index 226ab24a88..d2d6e495e1 100644 --- a/pypy/module/_winreg/interp_winreg.py +++ b/pypy/module/_winreg/interp_winreg.py @@ -328,8 +328,7 @@ def convert_to_regdata(space, w_value, typ): else: # REG_BINARY and ALL unknown data types. if space.is_w(w_value, space.w_None): buflen = 0 - buf = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw') - buf[0] = '\0' + buf = lltype.nullptr(rffi.CCHARP.TO) else: try: value = w_value.readbuf_w(space) @@ -385,7 +384,10 @@ def convert_from_regdata(space, buf, buflen, typ): return space.newlist(l) else: # REG_BINARY and all other types - return space.newbytes(rffi.charpsize2str(buf, buflen)) + if buflen == 0: + return space.w_None + else: + return space.newbytes(rffi.charpsize2str(buf, buflen)) @unwrap_spec(value_name="text", typ=int) def SetValueEx(space, w_hkey, value_name, w_reserved, typ, w_value): @@ -424,7 +426,8 @@ the configuration registry. This helps the registry perform efficiently.""" try: ret = rwinreg.RegSetValueExA(hkey, value_name, 0, typ, buf, buflen) finally: - lltype.free(buf, flavor='raw') + if buf != lltype.nullptr(rffi.CCHARP.TO): + lltype.free(buf, flavor='raw') if ret != 0: raiseWindowsError(space, ret, 'RegSetValueEx') diff --git a/pypy/module/_winreg/test/test_winreg.py b/pypy/module/_winreg/test/test_winreg.py index 73dad7bd15..a9ae368666 100644 --- a/pypy/module/_winreg/test/test_winreg.py +++ b/pypy/module/_winreg/test/test_winreg.py @@ -45,6 +45,7 @@ class AppTestFfi: ("Unicode Value", u"A unicode Value", _winreg.REG_SZ), ("Str Expand", "The path is %path%", _winreg.REG_EXPAND_SZ), ("Multi Str", ["Several", "string", u"values"], _winreg.REG_MULTI_SZ), + ("Raw None", None, _winreg.REG_BINARY), ("Raw data", "binary"+chr(0)+"data", _winreg.REG_BINARY), ] cls.w_test_data = space.wrap(test_data) |