git: ed56dcfc6b1f - main - boot: pass in args as const

From: Warner Losh <imp_at_FreeBSD.org>
Date: Wed, 07 Dec 2022 18:06:28 UTC
The branch main has been updated by imp:

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

commit ed56dcfc6b1f4de2a5ae4f0f86dff5dfe0a5541c
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-12-07 00:36:29 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-12-07 18:00:54 +0000

    boot: pass in args as const
    
    Copy the arg that sets a variable to maximize the reuse of this
    routine. There are places we call it from that are const char * and it
    might not be safe to cast that away.
    
    Sponsored by:           Netflix
---
 sys/kern/subr_boot.c | 13 +++++++++----
 sys/sys/boot.h       |  2 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/sys/kern/subr_boot.c b/sys/kern/subr_boot.c
index 82dd4195edfd..49c7769afce4 100644
--- a/sys/kern/subr_boot.c
+++ b/sys/kern/subr_boot.c
@@ -125,7 +125,7 @@ boot_howto_to_env(int howto)
  * variable and set that instead.
  */
 int
-boot_parse_arg(char *v)
+boot_parse_arg(const char *v)
 {
 	char *n;
 	int howto;
@@ -170,11 +170,16 @@ static int howto_masks[] = {
 			}
 		}
 	} else {
-		n = strsep(&v, "=");
-		if (v == NULL)
+		char buf[128];
+		char *vv = buf;
+
+		strlcpy(buf, v, sizeof(buf));
+		n = strsep(&vv, "=");
+		if (vv == NULL)
 			SETENV(n, "1");
 		else
-			SETENV(n, v);
+			SETENV(n, vv);
+		free(vv);
 	}
 #endif
 	return (howto);
diff --git a/sys/sys/boot.h b/sys/sys/boot.h
index 7874d9663736..26e39d70fd51 100644
--- a/sys/sys/boot.h
+++ b/sys/sys/boot.h
@@ -36,7 +36,7 @@
 
 int boot_env_to_howto(void);
 void boot_howto_to_env(int howto);
-int boot_parse_arg(char *v);
+int boot_parse_arg(const char *v);
 int boot_parse_cmdline_delim(char *cmdline, const char *delim);
 int boot_parse_cmdline(char *cmdline);
 int boot_parse_args(int argc, char *argv[]);