git: 274e8fff3162 - stable/13 - savecore: decrease filename buffer sizes

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 16 May 2022 13:51:19 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=274e8fff3162c5d5bd84dfe7240d3b463de12300

commit 274e8fff3162c5d5bd84dfe7240d3b463de12300
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-04-18 15:19:14 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-05-16 13:34:03 +0000

    savecore: decrease filename buffer sizes
    
    All files are now created relative to savedirfd, e.g. with openat(2).
    Therefore, we do not need character buffers to be PATH_MAX bytes long,
    just long enough to hold the complete filename. 32 bytes is long enough
    in all cases. These can be allocated on the stack.
    
    While here, fix an error message that attempts to use an uninitialized
    infoname.
    
    Reviewed by:    markj
    MFC after:      3 days
    Sponsored by:   Juniper Networks, Inc.
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D34821
    
    (cherry picked from commit fafeb5342b6402e112e00ecef4e4b49e894e2c11)
---
 sbin/savecore/savecore.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
index 755fef6bf31d..5e7a7115b0ad 100644
--- a/sbin/savecore/savecore.c
+++ b/sbin/savecore/savecore.c
@@ -318,7 +318,7 @@ file_size(int savedirfd, const char *path)
 static off_t
 saved_dump_size(int savedirfd, int bounds)
 {
-	static char path[PATH_MAX];
+	char path[32];
 	off_t dumpsize;
 
 	dumpsize = 0;
@@ -342,7 +342,7 @@ saved_dump_size(int savedirfd, int bounds)
 static void
 saved_dump_remove(int savedirfd, int bounds)
 {
-	static char path[PATH_MAX];
+	char path[32];
 
 	(void)snprintf(path, sizeof(path), "info.%d", bounds);
 	(void)unlinkat(savedirfd, path, 0);
@@ -697,10 +697,9 @@ DoTextdumpFile(int fd, off_t dumpsize, off_t lasthd, char *buf,
 static void
 DoFile(const char *savedir, int savedirfd, const char *device)
 {
-	xo_handle_t *xostdout, *xoinfo;
-	static char infoname[PATH_MAX], corename[PATH_MAX], linkname[PATH_MAX];
-	static char keyname[PATH_MAX];
 	static char *buf = NULL;
+	xo_handle_t *xostdout, *xoinfo;
+	char infoname[32], corename[32], linkname[32], keyname[32];
 	char *temp = NULL;
 	struct kerneldumpheader kdhf, kdhl;
 	uint8_t *dumpkey;
@@ -719,7 +718,7 @@ DoFile(const char *savedir, int savedirfd, const char *device)
 
 	xostdout = xo_create_to_file(stdout, XO_STYLE_TEXT, 0);
 	if (xostdout == NULL) {
-		logmsg(LOG_ERR, "%s: %m", infoname);
+		logmsg(LOG_ERR, "xo_create_to_file() failed: %m");
 		return;
 	}