Skip to content

Commit

Permalink
Fix memory error when running interactive mode with long command line (
Browse files Browse the repository at this point in the history
…#959)

* Protect against memory overflow when running interactive mode with a long command line

* 6.4.4. Revision bump for memory overflow with interactive mode + long command line fix.

* Fix printf format

* Protect against potential buffer overruns
  • Loading branch information
drroe authored Mar 18, 2022
1 parent ebce523 commit 1b624bd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Action_Keep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Action::RetType Action_Keep::Setup(ActionSetup& setup)
if (resSize == -1)
resSize = setup.Top().Res(*rnum).NumAtoms();
else if (setup.Top().Res(*rnum).NumAtoms() != resSize) {
mprinterr("Error: Residue '%s' size (%i) != first residue size (%s)\n",
mprinterr("Error: Residue '%s' size (%i) != first residue size (%i)\n",
setup.Top().TruncResNameNum(*rnum).c_str(),
setup.Top().Res(*rnum).NumAtoms(), resSize);
return Action::ERR;
Expand Down
7 changes: 5 additions & 2 deletions src/Cpptraj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,11 @@ int Cpptraj::Interactive() {
if (logfile_.IsOpen()) {
// Write logfile header entry: date, cmd line opts, topologies
logfile_.Printf("# %s\n", TimeString().c_str());
if (!commandLine_.empty())
logfile_.Printf("# Args: %s\n", commandLine_.c_str());
if (!commandLine_.empty()) {
logfile_.Printf("# Args: ");
logfile_.Write(commandLine_.c_str(), commandLine_.size());
logfile_.Printf("\n");
}
DataSetList tops = State_.DSL().GetSetsOfType("*", DataSet::TOPOLOGY);
if (!tops.empty()) {
logfile_.Printf("# Loaded topologies:\n");
Expand Down
2 changes: 1 addition & 1 deletion src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Whenever a number that precedes <revision> is incremented, all subsequent
* numbers should be reset to 0.
*/
#define CPPTRAJ_INTERNAL_VERSION "V6.4.3"
#define CPPTRAJ_INTERNAL_VERSION "V6.4.4"
/// PYTRAJ relies on this
#define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION
#endif
6 changes: 3 additions & 3 deletions src/vmdplugin/dtrplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static inline std::string addslash(const std::string& s){
return (s.rbegin()[0] == '/') ? s : s + "/";
}

#define DD_RELPATH_MAXLEN (9)
#define DD_RELPATH_MAXLEN (32)
static std::string
DDreldir(const std::string& fname, int ndir1, int ndir2){

Expand Down Expand Up @@ -712,15 +712,15 @@ void DDmkdir(const std::string &dirpath, mode_t mode, int ndir1, int ndir2){
throw DDException("fclose(.ddparams)", errno);

for(int i=0; i<ndir1; ++i){
char sub[6];
char sub[16];
sprintf(sub, "%03x/", i);
std::string dirsub = dpslash + sub;
{
if( mkdir(dirsub.c_str(), openmode) < 0 )
throw DDException("mkdir " + dirsub, errno);
}
for(int j=0; j<ndir2; ++j){
char subsub[6];
char subsub[16];
sprintf(subsub, "%03x", j);
std::string dirsubsub = dirsub + subsub;
if( mkdir(dirsubsub.c_str(), mode) < 0 ) // NOT openmode!
Expand Down

0 comments on commit 1b624bd

Please sign in to comment.