Project

General

Profile

Bug #12192

python3 modules treat strings incorrectly

Added by Alexander Pyhalov 11 months ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

When we try to use python3.5 pyzfs, we get

python3.5 /usr/lib/zfs/pyzfs.py allow alp mount data/zones
Traceback (most recent call last):
  File "/usr/lib/zfs/pyzfs.py", line 68, in <module>
    subfunc()
  File "/usr/lib/python3.5/vendor-packages/zfs/allow.py", line 395, in do_allow
    ds.set_fsacl(un, d)
  File "/usr/lib/python3.5/vendor-packages/zfs/dataset.py", line 198, in set_fsacl
    return zfs.ioctl.set_fsacl(self.name, un, d)
KeyError: 'ul$101'

This is because strings are treated incorrectly as bytes in ioctl.c. The following seems to fix the issue.

--- a/usr/src/lib/pyzfs/common/ioctl.c
+++ b/usr/src/lib/pyzfs/common/ioctl.c
@@ -144,7 +144,7 @@ dict2nvl(PyObject *d)

        while (PyDict_Next(d, &pos, &key, &value)) {
 #if PY_MAJOR_VERSION >= 3
-               char *keystr = PyBytes_AsString(key);
+               char *keystr = PyUnicode_AsUTF8(key);
 #else
                char *keystr = PyString_AsString(key);
 #endif
@@ -161,12 +161,12 @@ dict2nvl(PyObject *d)
                } else if (value == Py_None) {
                        err = nvlist_add_boolean(nvl, keystr);
 #if PY_MAJOR_VERSION >= 3
-               } else if (PyBytes_Check(value)) {
+               } else if (PyUnicode_Check(value)) {
 #else
                } else if (PyString_Check(value)) {
 #endif
 #if PY_MAJOR_VERSION >= 3
-                       char *valstr = PyBytes_AsString(value);
+                       char *valstr = PyUnicode_AsUTF8(value);
 #else
                        char *valstr = PyString_AsString(value);
 #endif


Related issues

Related to illumos gate - Bug #11522: illumos-gate has some runtime dependencies on Python 2.7Closed

Actions
Related to illumos gate - Bug #12215: pyzfs module does not build with python 3.7ClosedAndy Fiddaman

Actions
#1

Updated by Alexander Pyhalov 11 months ago

  • Subject changed from zfs python3 modules treat strings incorrectly to python3 modules treat strings incorrectly
#2

Updated by Alexander Pyhalov 11 months ago

The same issue can be seen in libbe_py:

# python3.5
Python 3.5.7 (default, May  2 2019, 18:24:52) 
[GCC 6.5.0] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import libbe_py as be
>>> be.beCopy('test', 'openindiana-2019:12:19-backup-1',None, None, {'ru.rsu.cc:test':'value'})
Assertion failed: PyBytes_Check(pvalue), file ../common/libbe_py.c, line 207, function beCopy
Abort (core dumped)

#3

Updated by Dan McDonald 11 months ago

See #11522 for testing information.

#4

Updated by Dan McDonald 11 months ago

  • Related to Bug #11522: illumos-gate has some runtime dependencies on Python 2.7 added
#5

Updated by Electric Monk 11 months ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit b0858fdc3790ef1d1f955bd584621c6fd539050d

commit  b0858fdc3790ef1d1f955bd584621c6fd539050d
Author: Alexander Pyhalov <apyhalov@gmail.com>
Date:   2020-01-15T20:23:30.000Z

    11522 illumos-gate has some runtime dependencies on Python 2.7
    12192 python3 modules treat strings incorrectly
    Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
    Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk>
    Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Approved by: Dan McDonald <danmcd@joyent.com>

#6

Updated by Andy Fiddaman 10 months ago

  • Related to Bug #12215: pyzfs module does not build with python 3.7 added

Also available in: Atom PDF