Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #47 from jvm3487/segFaultFix
Browse files Browse the repository at this point in the history
Fix malloc off-by-one seg fault due to not accounting for the null terminator
  • Loading branch information
ManofWax authored Jul 26, 2018
2 parents 80d5421 + 3e9a380 commit b038a4d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fw1-cursor.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "fw1-cursor.h"

#define CURSOR_FILE_EXT ".cursor"

int read_fw1_cursorfile () {
rewind (cursorstream);
fgets (cursorline, (POSITION_MAX_SIZE + 1), cursorstream);
Expand Down Expand Up @@ -35,14 +37,14 @@ int write_fw1_cursorfile (const char *message, const char separator) {

char* get_fw1_cursorname(const char *LogfileName) {
char *cursorname =
(char *) malloc (strlen (LogfileName) + 7);
(char *) malloc (sizeof(char) * (strlen (LogfileName) + strlen (CURSOR_FILE_EXT) + 1));
if (cursorname == NULL)
{
fprintf (stderr, "ERROR: Out of memory\n");
exit(EXIT_FAILURE);
}
strcpy (cursorname, LogfileName);
strcat (cursorname, ".cursor");
strcat (cursorname, CURSOR_FILE_EXT);

return cursorname;
}
Expand Down

0 comments on commit b038a4d

Please sign in to comment.