[27739] in Source-Commits
python-afs commit: Don't attempt to use sizeof() on a pointer
daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Wed Feb 26 16:22:02 2014
Date: Wed, 26 Feb 2014 16:21:55 -0500
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201402262121.s1QLLtbf015705@drugstore.mit.edu>
To: source-commits@MIT.EDU
https://github.com/mit-athena/python-afs/commits/efa96ae17765934cd3b4071628fed80370d64327
commit efa96ae17765934cd3b4071628fed80370d64327
Author: Jonathan Reed <jdreed@mit.edu>
Date: Thu Feb 20 13:16:55 2014 -0500
Don't attempt to use sizeof() on a pointer
The change added in 279058d8 never actually worked, because
calling sizeof() on a pointer to a buffer does not in fact get you
the size of the buffer. (Rather, it worked fine provided you
didn't want more than 8 bytes back.)
Update pioctl_write() to take a parameter for the size of the
output buffer, and update calls to pioctl_write in _fs.pyx and
_acl.pyx
afs/_acl.pyx | 2 +-
afs/_fs.pyx | 2 +-
afs/_util.pxd | 2 +-
afs/_util.pyx | 6 ++++--
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/afs/_acl.pyx b/afs/_acl.pyx
index a57bd07..d67885c 100644
--- a/afs/_acl.pyx
+++ b/afs/_acl.pyx
@@ -45,4 +45,4 @@ def getCallerAccess(char *dir, int follow=1):
return stat.callerAccess
def setAcl(char* dir, char* acl, int follow=1):
- pioctl_write(dir, VIOCSETAL, acl, NULL, follow)
+ pioctl_write(dir, VIOCSETAL, acl, NULL, 0, follow)
diff --git a/afs/_fs.pyx b/afs/_fs.pyx
index 465da67..0ee3359 100644
--- a/afs/_fs.pyx
+++ b/afs/_fs.pyx
@@ -26,7 +26,7 @@ def _lsmount(char* parent, char* path):
"""
cdef char mtpt[AFS_PIOCTL_MAXSIZE]
- pioctl_write(parent, VIOC_AFS_STAT_MT_PT, path, mtpt, 1)
+ pioctl_write(parent, VIOC_AFS_STAT_MT_PT, path, mtpt, sizeof(mtpt), 1)
return mtpt
def _volume_status(char* path):
diff --git a/afs/_util.pxd b/afs/_util.pxd
index 3d9bcd3..49db7f1 100644
--- a/afs/_util.pxd
+++ b/afs/_util.pxd
@@ -204,5 +204,5 @@ cdef struct VenusFid:
# pioctl doesn't actually have a header, so we have to define it here
cdef extern int pioctl(char *, afs_int32, ViceIoctl *, afs_int32)
cdef int pioctl_read(char *, afs_int32, void *, unsigned short, afs_int32) except -1
-cdef int pioctl_write(char *, afs_int32, char *, void *, afs_int32) except -1
+cdef int pioctl_write(char *, afs_int32, char *, void *, afs_int32, afs_int32) except -1
diff --git a/afs/_util.pyx b/afs/_util.pyx
index 99c0609..c3f9770 100644
--- a/afs/_util.pyx
+++ b/afs/_util.pyx
@@ -39,8 +39,10 @@ cdef extern int pioctl_read(char *path, afs_int32 op, void *outbuffer,
# "outbuffer" will get populated with the data in question
# Pass NULL for outbuffer in cases where we don't get anything
# back (e.g. VIOCSETAL)
+# "outsize" will be ignored (forced to 0) if "outbuffer" is NULL
cdef extern int pioctl_write(char *path, afs_int32 op, char *inbuffer,
- void *outbuffer, afs_int32 follow) except -1:
+ void *outbuffer, afs_int32 outsize,
+ afs_int32 follow) except -1:
cdef ViceIoctl blob
cdef afs_int32 code
blob.cin = inbuffer
@@ -51,7 +53,7 @@ cdef extern int pioctl_write(char *path, afs_int32 op, char *inbuffer,
log.debug("No output desired from pioctl_write()")
blob.out_size = 0
else:
- blob.out_size = sizeof(outbuffer)
+ blob.out_size = outsize
blob.out = outbuffer
code = pioctl(path, op, &blob, follow)
log.debug("pioctl_write() returned %d", code)