s390/boot: Use strspcy() instead of strcpy()
authorHeiko Carstens <hca@linux.ibm.com>
Thu, 24 Apr 2025 09:27:09 +0000 (11:27 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Wed, 30 Apr 2025 09:41:28 +0000 (11:41 +0200)
Convert all strcpy() usages to strscpy(). strcpy() is deprecated since
it performs no bounds checking on the destination buffer.

Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/boot/ipl_parm.c
arch/s390/boot/printk.c

index 16b6809e628aa430ed5919b3b1b0edec82af9a6d..f584d7da29cb204fb88de629be92d5aa822a866e 100644 (file)
@@ -179,7 +179,7 @@ void setup_boot_command_line(void)
        if (has_ebcdic_char(parmarea.command_line))
                EBCASC(parmarea.command_line, COMMAND_LINE_SIZE);
        /* copy arch command line */
-       strcpy(early_command_line, strim(parmarea.command_line));
+       strscpy(early_command_line, strim(parmarea.command_line));
 
        /* append IPL PARM data to the boot command line */
        if (!is_prot_virt_guest() && ipl_block_valid)
@@ -253,7 +253,8 @@ void parse_boot_command_line(void)
        int rc;
 
        __kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
-       args = strcpy(command_line_buf, early_command_line);
+       strscpy(command_line_buf, early_command_line);
+       args = command_line_buf;
        while (*args) {
                args = next_arg(args, &param, &val);
 
index 8f3b2244ef1b66ee65e219363aaba03e482aeb5b..4bb6bc95704e2a6e30d9a31d02286398e2b595e1 100644 (file)
@@ -29,7 +29,8 @@ static void boot_rb_add(const char *str, size_t len)
        /* store strings separated by '\0' */
        if (len + 1 > avail)
                boot_rb_off = 0;
-       strcpy(boot_rb + boot_rb_off, str);
+       avail = sizeof(boot_rb) - boot_rb_off - 1;
+       strscpy(boot_rb + boot_rb_off, str, avail);
        boot_rb_off += len + 1;
 }
 
@@ -161,7 +162,7 @@ static noinline char *strsym(char *buf, void *ip)
                strscpy(buf, p, MAX_SYMLEN);
                /* reserve 15 bytes for offset/len in symbol+0x1234/0x1234 */
                p = buf + strnlen(buf, MAX_SYMLEN - 15);
-               strcpy(p, "+0x");
+               strscpy(p, "+0x", MAX_SYMLEN - (p - buf));
                as_hex(p + 3, off, 0);
                strcat(p, "/0x");
                as_hex(p + strlen(p), len, 0);