Author: aconway
Date: Wed Jan 6 18:49:52 2010
New Revision: 896617
URL: http://svn.apache.org/viewvc?rev=896617&view=rev
Log:
Fix uninitialized read error in cluster::StoreStatus.
Modified:
qpid/trunk/qpid/cpp/src/qpid/cluster/StoreStatus.cpp
Modified: qpid/trunk/qpid/cpp/src/qpid/cluster/StoreStatus.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/StoreStatus.cpp?rev=896617&r1=896616&r2=896617&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/StoreStatus.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/StoreStatus.cpp Wed Jan 6 18:49:52
2010
@@ -31,7 +31,7 @@
using framing::Uuid;
using namespace framing::cluster;
namespace fs=boost::filesystem;
-using std::ostream;
+using namespace std;
StoreStatus::StoreStatus(const std::string& d)
: state(STORE_STATE_NO_STORE), dataDir(d), configSeq(0)
@@ -44,10 +44,16 @@
const char* SHUTDOWN_ID_FILE="shutdown.uuid";
const char* CONFIG_SEQ_FILE="config.seq";
+void throw_exceptions(ios& ios) {
+ // Have stream throw an exception on error.
+ ios.exceptions(std::ios::badbit | std::ios::failbit);
+}
+
Uuid loadUuid(const fs::path& path) {
Uuid ret;
if (exists(path)) {
fs::ifstream i(path);
+ throw_exceptions(i);
i >> ret;
}
return ret;
@@ -55,9 +61,20 @@
void saveUuid(const fs::path& path, const Uuid& uuid) {
fs::ofstream o(path);
+ throw_exceptions(o);
o << uuid;
}
+framing::SequenceNumber loadSeqNum(const fs::path& path) {
+ uint32_t n = 0;
+ if (exists(path)) {
+ fs::ifstream i(path);
+ throw_exceptions(i);
+ i >> n;
+ }
+ return framing::SequenceNumber(n);
+}
+
} // namespace
@@ -67,10 +84,7 @@
create_directory(dir);
clusterId = loadUuid(dir/CLUSTER_ID_FILE);
shutdownId = loadUuid(dir/SHUTDOWN_ID_FILE);
- fs::ifstream is(dir/CONFIG_SEQ_FILE);
- uint32_t n;
- is >> n;
- configSeq = framing::SequenceNumber(n);
+ configSeq = loadSeqNum(dir/CONFIG_SEQ_FILE);
if (clusterId && shutdownId) state = STORE_STATE_CLEAN_STORE;
else if (clusterId) state = STORE_STATE_DIRTY_STORE;
else state = STORE_STATE_EMPTY_STORE;
@@ -86,8 +100,9 @@
create_directory(dir);
saveUuid(dir/CLUSTER_ID_FILE, clusterId);
saveUuid(dir/SHUTDOWN_ID_FILE, shutdownId);
- fs::ofstream os(dir/CONFIG_SEQ_FILE);
- os << configSeq.getValue();
+ fs::ofstream o(dir/CONFIG_SEQ_FILE);
+ throw_exceptions(o);
+ o << configSeq.getValue();
}
catch (const std::exception&e) {
throw Exception(QPID_MSG("Cannot save cluster store status: " <<
e.what()));
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]