Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions libpromises/files_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,31 @@ bool SaveAsFile(EvalContext *ctx, SaveCallbackFn callback, void *param, const ch
}
}

strcpy(backup, BufferData(deref_file));
const char *deref = BufferData(deref_file);

strlcpy(backup, deref, sizeof(backup));

if (a->edits.backup == BACKUP_OPTION_TIMESTAMP)
{
snprintf(stamp, CF_BUFSIZE, "_%jd_%s", (intmax_t) CFSTARTTIME, CanonifyName(ctime(&stamp_now)));
strcat(backup, stamp);
strlcat(backup, stamp, sizeof(backup));
}

strcat(backup, ".cf-before-edit");
if (strlcat(backup, ".cf-before-edit", sizeof(backup)) >= sizeof(backup))
{
Log(LOG_LEVEL_ERR,
"Filename too long to create backup for editing: %s",
BufferData(pretty_file));
goto end;
}

strcpy(new, BufferData(deref_file));
strcat(new, ".cf-after-edit");
if (strlcpy(new, deref, sizeof(new)) >= sizeof(new) ||
strlcat(new, ".cf-after-edit", sizeof(new)) >= sizeof(new))
{
Log(LOG_LEVEL_ERR, "Filename too long to edit: %s",
BufferData(pretty_file));
goto end;
}
unlink(new); /* Just in case of races */

if ((*callback)(new, param, new_line_mode) == false)
Expand Down
Loading