Fix string overwrite bug.

This commit is contained in:
Adam Ierymenko 2015-07-20 14:31:33 -07:00
parent 1ffd67e014
commit fb4c3dd8d4

View File

@ -925,8 +925,9 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST(
for(std::map<Address,InetAddress>::iterator rl(nodeIdToPhyAddress.begin());rl!=nodeIdToPhyAddress.end();++rl) { for(std::map<Address,InetAddress>::iterator rl(nodeIdToPhyAddress.begin());rl!=nodeIdToPhyAddress.end();++rl) {
sqlite3_reset(_sCreateRelay); sqlite3_reset(_sCreateRelay);
sqlite3_bind_text(_sCreateRelay,1,nwids,16,SQLITE_STATIC); sqlite3_bind_text(_sCreateRelay,1,nwids,16,SQLITE_STATIC);
sqlite3_bind_text(_sCreateRelay,2,rl->first.toString().c_str(),-1,SQLITE_STATIC); std::string a(rl->first.toString()),b(rl->second.toString()); // don't destroy strings until sqlite3_step()
sqlite3_bind_text(_sCreateRelay,3,rl->second.toString().c_str(),-1,SQLITE_STATIC); sqlite3_bind_text(_sCreateRelay,2,a.c_str(),-1,SQLITE_STATIC);
sqlite3_bind_text(_sCreateRelay,3,b.c_str(),-1,SQLITE_STATIC);
sqlite3_step(_sCreateRelay); sqlite3_step(_sCreateRelay);
} }
} }