summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Marko <peter.marko@siemens.com>2025-03-11 19:14:09 +0100
committerSteve Sakoman <steve@sakoman.com>2025-03-15 06:44:47 -0700
commit039f52ed9c3e3f7326eef84c3175677591d8b38a (patch)
tree7363ef9f93ee62d05ca22e663c75c05e8d0144f2
parenteafe151f69beee757046540380a1e42d7fc4740a (diff)
downloadpoky-039f52ed9c3e3f7326eef84c3175677591d8b38a.tar.gz
grub: backport strlcpy function
It is used to fix multiple CVEs. (From OE-Core rev: 48cf877397b82449f171190a33a8e723512b8227) Signed-off-by: Peter Marko <peter.marko@siemens.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-bsp/grub/files/0001-misc-Implement-grub_strlcpy.patch68
-rw-r--r--meta/recipes-bsp/grub/grub2.inc1
2 files changed, 69 insertions, 0 deletions
diff --git a/meta/recipes-bsp/grub/files/0001-misc-Implement-grub_strlcpy.patch b/meta/recipes-bsp/grub/files/0001-misc-Implement-grub_strlcpy.patch
new file mode 100644
index 0000000000..0ff6dff33a
--- /dev/null
+++ b/meta/recipes-bsp/grub/files/0001-misc-Implement-grub_strlcpy.patch
@@ -0,0 +1,68 @@
1From ea703528a8581a2ea7e0bad424a70fdf0aec7d8f Mon Sep 17 00:00:00 2001
2From: B Horn <b@horn.uk>
3Date: Sat, 15 Jun 2024 02:33:08 +0100
4Subject: [PATCH 1/2] misc: Implement grub_strlcpy()
5
6grub_strlcpy() acts the same way as strlcpy() does on most *NIX,
7returning the length of src and ensuring dest is always NUL
8terminated except when size is 0.
9
10Signed-off-by: B Horn <b@horn.uk>
11Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
12
13Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/grub.git/commit/?id=ea703528a8581a2ea7e0bad424a70fdf0aec7d8f]
14Signed-off-by: Peter Marko <peter.marko@siemens.com>
15---
16 include/grub/misc.h | 39 +++++++++++++++++++++++++++++++++++++++
17 1 file changed, 39 insertions(+)
18
19diff --git a/include/grub/misc.h b/include/grub/misc.h
20index 1578f36c3..14d8f37ac 100644
21--- a/include/grub/misc.h
22+++ b/include/grub/misc.h
23@@ -64,6 +64,45 @@ grub_stpcpy (char *dest, const char *src)
24 return d - 1;
25 }
26
27+static inline grub_size_t
28+grub_strlcpy (char *dest, const char *src, grub_size_t size)
29+{
30+ char *d = dest;
31+ grub_size_t res = 0;
32+ /*
33+ * We do not subtract one from size here to avoid dealing with underflowing
34+ * the value, which is why to_copy is always checked to be greater than one
35+ * throughout this function.
36+ */
37+ grub_size_t to_copy = size;
38+
39+ /* Copy size - 1 bytes to dest. */
40+ if (to_copy > 1)
41+ while ((*d++ = *src++) != '\0' && ++res && --to_copy > 1)
42+ ;
43+
44+ /*
45+ * NUL terminate if size != 0. The previous step may have copied a NUL byte
46+ * if it reached the end of the string, but we know dest[size - 1] must always
47+ * be a NUL byte.
48+ */
49+ if (size != 0)
50+ dest[size - 1] = '\0';
51+
52+ /* If there is still space in dest, but are here, we reached the end of src. */
53+ if (to_copy > 1)
54+ return res;
55+
56+ /*
57+ * If we haven't reached the end of the string, iterate through to determine
58+ * the strings total length.
59+ */
60+ while (*src++ != '\0' && ++res)
61+ ;
62+
63+ return res;
64+}
65+
66 /* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */
67 static inline void *
68 grub_memcpy (void *dest, const void *src, grub_size_t n)
diff --git a/meta/recipes-bsp/grub/grub2.inc b/meta/recipes-bsp/grub/grub2.inc
index c93b9594c8..43ba632ce2 100644
--- a/meta/recipes-bsp/grub/grub2.inc
+++ b/meta/recipes-bsp/grub/grub2.inc
@@ -18,6 +18,7 @@ SRC_URI = "${GNU_MIRROR}/grub/grub-${PV}.tar.gz \
18 file://grub-module-explicitly-keeps-symbole-.module_license.patch \ 18 file://grub-module-explicitly-keeps-symbole-.module_license.patch \
19 file://0001-grub.d-10_linux.in-add-oe-s-kernel-name.patch \ 19 file://0001-grub.d-10_linux.in-add-oe-s-kernel-name.patch \
20 file://0001-RISC-V-Restore-the-typcast-to-long.patch \ 20 file://0001-RISC-V-Restore-the-typcast-to-long.patch \
21 file://0001-misc-Implement-grub_strlcpy.patch \
21" 22"
22 23
23SRC_URI[sha256sum] = "b30919fa5be280417c17ac561bb1650f60cfb80cc6237fa1e2b6f56154cb9c91" 24SRC_URI[sha256sum] = "b30919fa5be280417c17ac561bb1650f60cfb80cc6237fa1e2b6f56154cb9c91"