From 1b624bd56bd8b2a4672238a77c750da2f7145213 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 18 Mar 2022 15:10:23 -0400 Subject: [PATCH] Fix memory error when running interactive mode with long command line (#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 --- src/Action_Keep.cpp | 2 +- src/Cpptraj.cpp | 7 +++++-- src/Version.h | 2 +- src/vmdplugin/dtrplugin.cpp | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Action_Keep.cpp b/src/Action_Keep.cpp index f73fe62ae5..a70016acbf 100644 --- a/src/Action_Keep.cpp +++ b/src/Action_Keep.cpp @@ -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; diff --git a/src/Cpptraj.cpp b/src/Cpptraj.cpp index f6857fab2f..5d94b8dacb 100644 --- a/src/Cpptraj.cpp +++ b/src/Cpptraj.cpp @@ -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"); diff --git a/src/Version.h b/src/Version.h index 85d8f565bd..2c003ddddc 100644 --- a/src/Version.h +++ b/src/Version.h @@ -12,7 +12,7 @@ * Whenever a number that precedes 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 diff --git a/src/vmdplugin/dtrplugin.cpp b/src/vmdplugin/dtrplugin.cpp index cdaa7ff3ea..3f92f8de20 100644 --- a/src/vmdplugin/dtrplugin.cpp +++ b/src/vmdplugin/dtrplugin.cpp @@ -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){ @@ -712,7 +712,7 @@ void DDmkdir(const std::string &dirpath, mode_t mode, int ndir1, int ndir2){ throw DDException("fclose(.ddparams)", errno); for(int i=0; i