From 6c6b700233410dc702a2228b2bc8338b7967b672 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Thu, 22 Feb 2007 15:11:49 +0000 Subject: [PATCH] Stricter check on -p and associated fix in the php script git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@212 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- banana/mbox.inc.php | 48 +++++++++++++++++++++++------------------------ mbox-helper/mbox-helper.c | 4 ++-- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index db3a1fd..4f5e0bf 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -72,16 +72,7 @@ class BananaMBox implements BananaProtocoleInterface $id = Banana::$spool->ids[$id]; } $options = array ('-m ' . $id); - if (Banana::$spool->overview) { - if (Banana::$spool->overview[$id]) { - $options[] = '-p ' . $id . ':' . Banana::$spool->overview[$id]->storage['offset']; - } else { - $key = max(array_keys(Banana::$spool->overview)); - if ($key < $id) { - $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; - } - } - } + $this->getMBoxPosition($options, $id); return $this->callHelper('-b', $options); } @@ -114,10 +105,7 @@ class BananaMBox implements BananaProtocoleInterface private function getCount() { $options = array(); - if (Banana::$spool->overview) { - $key = max(array_keys(Banana::$spool->overview)); - $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; - } + $this->getMBoxPosition($options); $val =& $this->callHelper('-c', $options); if (!$val) { return 0; @@ -142,16 +130,7 @@ class BananaMBox implements BananaProtocoleInterface $headers = null; $options = array(); $options[] = "-m $firstid:$lastid"; - if (Banana::$spool->overview) { - if (isset(Banana::$spool->overview[$firstid])) { - $options[] = '-p ' . $firstid . ':' . Banana::$spool->overview[$firstid]->storage['offset']; - } else { - $key = max(array_keys(Banana::$spool->overview)); - if ($key < $firstid) { - $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; - } - } - } + $this->getMboxPosition($options, $firstid); $lines =& $this->callHelper('-d', $options, $msg_headers); if (!$lines) { return $headers; @@ -318,6 +297,25 @@ class BananaMBox implements BananaProtocoleInterface ####### # MBox parser ####### + + /** Add the '-p' optioin for callHelper + */ + private function getMBoxPosition(array &$option, $id = null) + { + if (Banana::$spool->overview) { + if (!is_null($id) && Banana::$spool->overview[$id]) { + $key = $id; + } else { + $key = max(array_keys(Banana::$spool->overview)); + if (!is_null($id) && $key >= $id) { + return; + } + } + if (isset(Banana::$spool->overview[$key]->storage['offset'])) { + $options[] = '-p ' . $key . ':' . Banana::$spool->overview[$key]->storage['offset']; + } + } + } private function &callHelper($action, array $options = array(), array $headers = array()) { @@ -329,7 +327,7 @@ class BananaMBox implements BananaProtocoleInterface exec($cmd, $out, $return); if ($this->debug) { $this->bt[] = array('action' => $cmd, 'time' => (microtime(true) - $start), - 'code' => $return, 'response' => count($out)); + 'code' => $return, 'response' => count($out), 'error' => $return ? "Helper failed" : null); } if ($return != 0) { $this->_lasterrorno = 1; diff --git a/mbox-helper/mbox-helper.c b/mbox-helper/mbox-helper.c index 49f1618..fae2087 100644 --- a/mbox-helper/mbox-helper.c +++ b/mbox-helper/mbox-helper.c @@ -331,7 +331,7 @@ int main(int argc, char *argv[]) if (endptr == optarg) { error("invalid message id"); } - if (*endptr != ':') { + if (*endptr != ':' || !*(endptr+1)) { lmid = fmid; } else { lmid = atoi(endptr + 1); @@ -340,7 +340,7 @@ int main(int argc, char *argv[]) case 'p': if ((endptr = strchr(optarg, ':')) != NULL) { pmid = strtol(optarg, &endptr, 10); - if (*endptr != ':') { + if (*endptr != ':' || !*(endptr+1)) { error("invalid position couple given"); } pos = atoi(endptr + 1); -- 2.1.4