diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-02-18 05:46:45 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-02-18 06:55:32 +0000 |
commit | 92b8a2091414c0024fe9fd35aed6891308c9dc26 (patch) | |
tree | 87e9cc18564ec7c5a42e6361bd71d742b1673e1a | |
parent | 719e4fc320e1978bc9ea6ee8be9f8249dcb54dab (diff) | |
download | cmogstored-92b8a2091414c0024fe9fd35aed6891308c9dc26.tar.gz |
sizeof(buf) returns the size of the pointer if buf is a passed parameter, even if it the function prototype dictates a fixed size for buf as we do in mog_iou_write. While we're at it, make our mog_iou_write buf parameter const. This bug was introduced in: commit a960a351b2248a196c91cdbf6256f98e1bc2ef37 "split iostat util% tracking from mountlist" and never affected an official release of cmogstored. This bug was caught while testing on a 32-bit GNU/Linux machine. My normal 32-bit FreeBSD 9.0 environment did not catch this as iostat on that platform only reports integer percentages and does not need more than 4 bytes.
-rw-r--r-- | cmogstored.h | 2 | ||||
-rw-r--r-- | ioutil.c | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/cmogstored.h b/cmogstored.h index d5f6137..73e1353 100644 --- a/cmogstored.h +++ b/cmogstored.h @@ -486,7 +486,7 @@ bool mog_valid_put_path(const char *buf, size_t len); void mog_iou_cleanup_begin(void); void mog_iou_cleanup_finish(void); void mog_iou_read(dev_t, char buf[MOG_IOUTIL_LEN]); -void mog_iou_write(dev_t, char buf[MOG_IOUTIL_LEN]); +void mog_iou_write(dev_t, const char buf[MOG_IOUTIL_LEN]); void mog_iou_active(dev_t); #include "activeq.h" @@ -121,17 +121,17 @@ void mog_iou_read(dev_t st_dev, char buf[MOG_IOUTIL_LEN]) CHECK(int, 0, pthread_mutex_lock(&iou_lock)); iou = iou_vivify(st_dev); - memcpy(buf, iou->util, sizeof(buf)); + memcpy(buf, iou->util, MOG_IOUTIL_LEN); CHECK(int, 0, pthread_mutex_unlock(&iou_lock)); } -void mog_iou_write(dev_t st_dev, char buf[MOG_IOUTIL_LEN]) +void mog_iou_write(dev_t st_dev, const char buf[MOG_IOUTIL_LEN]) { struct ioutil *iou; CHECK(int, 0, pthread_mutex_lock(&iou_lock)); iou = iou_vivify(st_dev); - memcpy(iou->util, buf, sizeof(iou->util)); + memcpy(iou->util, buf, MOG_IOUTIL_LEN); CHECK(int, 0, pthread_mutex_unlock(&iou_lock)); } |