Skip to content
Snippets Groups Projects
Unverified Commit 2faa34b2 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #1105 from rbberger/truncate-file-path

Avoid buffer overflow during errors with long filenames
parents 075d3660 ba1c5d31
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,7 @@ void Error::universe_all(const char *file, int line, const char *str) ...@@ -75,7 +75,7 @@ void Error::universe_all(const char *file, int line, const char *str)
update->whichflag = 0; update->whichflag = 0;
char msg[100]; char msg[100];
sprintf(msg, "ERROR: %s (%s:%d)\n", str, file, line); snprintf(msg, 100, "ERROR: %s (%s:%d)\n", str, truncpath(file), line);
throw LAMMPSException(msg); throw LAMMPSException(msg);
#else #else
MPI_Finalize(); MPI_Finalize();
...@@ -100,7 +100,7 @@ void Error::universe_one(const char *file, int line, const char *str) ...@@ -100,7 +100,7 @@ void Error::universe_one(const char *file, int line, const char *str)
update->whichflag = 0; update->whichflag = 0;
char msg[100]; char msg[100];
sprintf(msg, "ERROR: %s (%s:%d)\n", str, file, line); snprintf(msg, 100, "ERROR: %s (%s:%d)\n", str, truncpath(file), line);
throw LAMMPSAbortException(msg, universe->uworld); throw LAMMPSAbortException(msg, universe->uworld);
#else #else
MPI_Abort(universe->uworld,1); MPI_Abort(universe->uworld,1);
...@@ -151,7 +151,7 @@ void Error::all(const char *file, int line, const char *str) ...@@ -151,7 +151,7 @@ void Error::all(const char *file, int line, const char *str)
update->whichflag = 0; update->whichflag = 0;
char msg[100]; char msg[100];
sprintf(msg, "ERROR: %s (%s:%d)\n", str, file, line); snprintf(msg, 100, "ERROR: %s (%s:%d)\n", str, truncpath(file), line);
if (universe->nworlds > 1) { if (universe->nworlds > 1) {
throw LAMMPSAbortException(msg, universe->uworld); throw LAMMPSAbortException(msg, universe->uworld);
...@@ -201,7 +201,7 @@ void Error::one(const char *file, int line, const char *str) ...@@ -201,7 +201,7 @@ void Error::one(const char *file, int line, const char *str)
update->whichflag = 0; update->whichflag = 0;
char msg[100]; char msg[100];
sprintf(msg, "ERROR on proc %d: %s (%s:%d)\n", me, str, file, line); snprintf(msg, 100, "ERROR on proc %d: %s (%s:%d)\n", me, str, truncpath(file), line);
throw LAMMPSAbortException(msg, world); throw LAMMPSAbortException(msg, world);
#else #else
MPI_Abort(world,1); MPI_Abort(world,1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment