Skip to content

Commit 4ef9f1b

Browse files
author
dzsekijo
committed
Make the "fetchattr_soft" macro tolerate if the value of the given attribute is None.
This fixes the issue that returning an instance created by os.stat_result() from the "getattr" method caused EINVAL. Issue was reported by Forest Bond.
1 parent 83dc88a commit 4ef9f1b

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

fuseparts/_fusemodule.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fi_to_py(struct fuse_file_info *fi)
118118

119119
/* transform a Python integer to an unsigned C numeric value */
120120

121-
#define py2attr(st, attr) \
121+
#define py2attr(st, attr) { \
122122
if (PyInt_Check(pytmp) && sizeof((st)->attr) <= sizeof(long)) { \
123123
/* \
124124
* We'd rather use here PyInt_AsUnsignedLong() here \
@@ -162,8 +162,9 @@ fi_to_py(struct fuse_file_info *fi)
162162
goto OUT_DECREF; \
163163
(st)->attr = ctmp; \
164164
if ((unsigned long long)(st)->attr != ctmp) \
165-
goto OUT_DECREF;
166-
165+
goto OUT_DECREF; \
166+
}
167+
167168
#define fetchattr_nam(st, attr, aname) \
168169
if (!(pytmp = PyObject_GetAttrString(v, aname))) \
169170
goto OUT_DECREF; \
@@ -174,7 +175,13 @@ fi_to_py(struct fuse_file_info *fi)
174175

175176
#define fetchattr_soft(st, attr) \
176177
if (PyObject_HasAttrString(v, #attr)) { \
177-
fetchattr(st, attr); \
178+
pytmp = PyObject_GetAttrString(v, #attr); \
179+
if (!pytmp) \
180+
goto OUT_DECREF; \
181+
if (pytmp == Py_None) \
182+
Py_DECREF(pytmp); \
183+
else \
184+
py2attr(st, attr); \
178185
}
179186

180187
/*

0 commit comments

Comments
 (0)