summaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2020-10-12 13:58:28 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2020-10-12 13:58:28 +0000
commitfc3e3ab2ad7cd3bb895c1c6f8c0d0c117502b586 (patch)
treec0c80f409aa389e67f11ce370a69f58ad227d441 /usr.bin/patch
parentc54eb0aae682cd3fa3701ab00b27f23798792de0 (diff)
Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer. From Joerg Sonnenberger for DragonFly BSD. ok millert@
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/backupfile.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c
index d9e40bcba7e..ed0767762e0 100644
--- a/usr.bin/patch/backupfile.c
+++ b/usr.bin/patch/backupfile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: backupfile.c,v 1.21 2013/11/26 13:19:07 deraadt Exp $ */
+/* $OpenBSD: backupfile.c,v 1.22 2020/10/12 13:58:27 naddy Exp $ */
/*
* backupfile.c -- make Emacs style backup file names Copyright (C) 1990 Free
@@ -53,21 +53,32 @@ static void invalid_arg(const char *, const char *, int);
char *
find_backup_file_name(const char *file)
{
- char *dir, *base_versions;
+ char *dir, *base_versions, *tmp_file;
int highest_backup;
if (backup_type == simple)
return concat(file, simple_backup_suffix);
- base_versions = concat(basename(file), ".~");
+ tmp_file = strdup(file);
+ if (tmp_file == NULL)
+ return NULL;
+ base_versions = concat(basename(tmp_file), ".~");
+ free(tmp_file);
if (base_versions == NULL)
return NULL;
- dir = dirname(file);
+ tmp_file = strdup(file);
+ if (tmp_file == NULL) {
+ free(base_versions);
+ return NULL;
+ }
+ dir = dirname(tmp_file);
if (dir == NULL) {
free(base_versions);
+ free(tmp_file);
return NULL;
}
highest_backup = max_backup_version(base_versions, dir);
free(base_versions);
+ free(tmp_file);
if (backup_type == numbered_existing && highest_backup == 0)
return concat(file, simple_backup_suffix);
return make_version_name(file, highest_backup + 1);