aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2022-12-07 00:36:29 +0000
committerWarner Losh <imp@FreeBSD.org>2022-12-07 18:00:54 +0000
commited56dcfc6b1f4de2a5ae4f0f86dff5dfe0a5541c (patch)
tree023eaea0f2a2e3a62178381b155b9b6e0b10e796
parent482380c6f8252228a172d82e74ef0964f8fc258b (diff)
downloadsrc-ed56dcfc6b1f4de2a5ae4f0f86dff5dfe0a5541c.tar.gz
src-ed56dcfc6b1f4de2a5ae4f0f86dff5dfe0a5541c.zip
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
-rw-r--r--sys/kern/subr_boot.c13
-rw-r--r--sys/sys/boot.h2
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[]);