=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/patch/patch.c,v retrieving revision 1.74 retrieving revision 1.74.2.1 diff -c -r1.74 -r1.74.2.1 *** src/usr.bin/patch/patch.c 2023/07/19 13:26:20 1.74 --- src/usr.bin/patch/patch.c 2023/11/20 17:56:22 1.74.2.1 *************** *** 1,4 **** ! /* $OpenBSD: patch.c,v 1.74 2023/07/19 13:26:20 tb Exp $ */ /* * patch - a program to apply diffs to original files --- 1,4 ---- ! /* $OpenBSD: patch.c,v 1.74.2.1 2023/11/20 17:56:22 bluhm Exp $ */ /* * patch - a program to apply diffs to original files *************** *** 32,37 **** --- 32,38 ---- #include #include + #include #include #include #include *************** *** 213,223 **** perror("unveil"); my_exit(2); } ! if (filearg[0] != NULL) if (unveil(filearg[0], "rwc") == -1) { perror("unveil"); my_exit(2); } if (filearg[1] != NULL) if (unveil(filearg[1], "r") == -1) { perror("unveil"); --- 214,240 ---- perror("unveil"); my_exit(2); } ! if (filearg[0] != NULL) { ! char *origdir; ! if (unveil(filearg[0], "rwc") == -1) { perror("unveil"); my_exit(2); } + if ((origdir = dirname(filearg[0])) == NULL) { + perror("dirname"); + my_exit(2); + } + if (unveil(origdir, "rwc") == -1) { + perror("unveil"); + my_exit(2); + } + } else { + if (unveil(".", "rwc") == -1) { + perror("unveil"); + my_exit(2); + } + } if (filearg[1] != NULL) if (unveil(filearg[1], "r") == -1) { perror("unveil"); *************** *** 228,237 **** perror("unveil"); my_exit(2); } - if (unveil(".", "rwc") == -1) { - perror("unveil"); - my_exit(2); - } if (*rejname != '\0') if (unveil(rejname, "rwc") == -1) { perror("unveil"); --- 245,250 ----