* [PATCH master 1/4] efi: hide EFI related symbols when !EFI
@ 2024-06-11 6:57 Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 2/4] lib: wchar: guard against NULL in strdup_wchar Ahmad Fatoum
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-06-11 6:57 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In order not to clutter configs, we should hide symbols that are EFI
related when CONFIG_EFI is disabled, especially as we are going to add
more options with the loader support.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/Kconfig | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/efi/Kconfig b/efi/Kconfig
index 3bda02600c94..dfe4d7327084 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -23,6 +23,8 @@ config EFI
config HAVE_EFI_STUB
bool
+if EFI
+
config EFI_STUB
def_bool EFI_PAYLOAD
depends on HAVE_EFI_STUB
@@ -45,4 +47,6 @@ config EFI_PAYLOAD_DEFAULT_PATH
default "EFI/BOOT/BOOTRISCV64.EFI" if ARCH_RV64I
default "EFI/BOOT/BAREBOX.EFI"
+endif
+
endmenu
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH master 2/4] lib: wchar: guard against NULL in strdup_wchar
2024-06-11 6:57 [PATCH master 1/4] efi: hide EFI related symbols when !EFI Ahmad Fatoum
@ 2024-06-11 6:57 ` Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 3/4] efi: payload: gracefully handle NULL parent image device path Ahmad Fatoum
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-06-11 6:57 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
strdup(NULL) returns NULL, so the wchar_t-Variants should behave
the same way.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/wchar.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/wchar.c b/lib/wchar.c
index 250538dd8511..49e946a09424 100644
--- a/lib/wchar.c
+++ b/lib/wchar.c
@@ -39,9 +39,13 @@ size_t wcsnlen(const wchar_t * s, size_t count)
wchar_t *strdup_wchar(const wchar_t *src)
{
- int len = wcslen(src);
+ int len;
wchar_t *tmp, *dst;
+ if (!src)
+ return NULL;
+
+ len = wcslen(src);
if (!(dst = malloc((len + 1) * sizeof(wchar_t))))
return NULL;
@@ -97,8 +101,9 @@ wchar_t *strcpy_char_to_wchar(wchar_t *dst, const char *src)
wchar_t *strdup_char_to_wchar(const char *src)
{
- wchar_t *dst = malloc((strlen(src) + 1) * sizeof(wchar_t));
+ wchar_t *dst;
+ dst = src ? malloc((strlen(src) + 1) * sizeof(wchar_t)) : NULL;
if (!dst)
return NULL;
@@ -109,8 +114,9 @@ wchar_t *strdup_char_to_wchar(const char *src)
char *strdup_wchar_to_char(const wchar_t *src)
{
- char *dst = malloc((wcslen(src) + 1));
+ char *dst;
+ dst = src ? malloc((wcslen(src) + 1)) : NULL;
if (!dst)
return NULL;
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH master 3/4] efi: payload: gracefully handle NULL parent image device path
2024-06-11 6:57 [PATCH master 1/4] efi: hide EFI related symbols when !EFI Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 2/4] lib: wchar: guard against NULL in strdup_wchar Ahmad Fatoum
@ 2024-06-11 6:57 ` Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 4/4] fs: legacy: gracefully handle non existent files Ahmad Fatoum
2024-06-13 7:30 ` [PATCH master 1/4] efi: hide EFI related symbols when !EFI Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-06-11 6:57 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
device_path_to_filepath may be called on a device pth that contains no
file path. In that case, the function should return NULL instead of
dereferencing the NULL pointer. Fix this.
Fixes: f1230c7f92cd ("efi: payload: dynamically determine bootloader file name")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/devicepath.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/efi/devicepath.c b/efi/devicepath.c
index 23963aa0cbb7..ecb3e7b64cc1 100644
--- a/efi/devicepath.c
+++ b/efi/devicepath.c
@@ -824,6 +824,9 @@ char *device_path_to_filepath(const struct efi_device_path *dev_path)
dev_path = next_device_path_node(&fp->header);
}
+ if (!fp)
+ return NULL;
+
path = strdup_wchar_to_char(fp->path_name);
if (!path)
return NULL;
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH master 4/4] fs: legacy: gracefully handle non existent files
2024-06-11 6:57 [PATCH master 1/4] efi: hide EFI related symbols when !EFI Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 2/4] lib: wchar: guard against NULL in strdup_wchar Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 3/4] efi: payload: gracefully handle NULL parent image device path Ahmad Fatoum
@ 2024-06-11 6:57 ` Ahmad Fatoum
2024-06-13 7:30 ` [PATCH master 1/4] efi: hide EFI related symbols when !EFI Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-06-11 6:57 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The Semihosting file system API doesn't support listing files, so the
opendir callback returns NULL. This triggers crashes inside the legacy
dentry adapter code, so add some NULL checks to guard against this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/legacy.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/legacy.c b/fs/legacy.c
index 7e886e7ae9a2..0d4d4d43ebac 100644
--- a/fs/legacy.c
+++ b/fs/legacy.c
@@ -29,6 +29,9 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
d = fsdev->driver->opendir(&fsdev->dev, pathname);
+ if (!d)
+ goto out;
+
while (1) {
dirent = fsdev->driver->readdir(&fsdev->dev, d);
if (!dirent)
@@ -38,7 +41,7 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
}
fsdev->driver->closedir(&fsdev->dev, d);
-
+out:
free(pathname);
return 0;
@@ -55,10 +58,14 @@ static struct dentry *legacy_lookup(struct inode *dir, struct dentry *dentry,
int ret;
pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
+ if (!pathname)
+ return NULL;
ret = fsdev->driver->stat(&fsdev->dev, pathname, &s);
if (!ret) {
inode = legacy_get_inode(sb, dir, s.st_mode);
+ if (!inode)
+ return NULL;
inode->i_size = s.st_size;
inode->i_mode = s.st_mode;
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH master 1/4] efi: hide EFI related symbols when !EFI
2024-06-11 6:57 [PATCH master 1/4] efi: hide EFI related symbols when !EFI Ahmad Fatoum
` (2 preceding siblings ...)
2024-06-11 6:57 ` [PATCH master 4/4] fs: legacy: gracefully handle non existent files Ahmad Fatoum
@ 2024-06-13 7:30 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-06-13 7:30 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Tue, 11 Jun 2024 08:57:15 +0200, Ahmad Fatoum wrote:
> In order not to clutter configs, we should hide symbols that are EFI
> related when CONFIG_EFI is disabled, especially as we are going to add
> more options with the loader support.
>
>
Applied, thanks!
[1/4] efi: hide EFI related symbols when !EFI
https://git.pengutronix.de/cgit/barebox/commit/?id=7ac8732a6cec (link may not be stable)
[2/4] lib: wchar: guard against NULL in strdup_wchar
https://git.pengutronix.de/cgit/barebox/commit/?id=47d910fe2706 (link may not be stable)
[3/4] efi: payload: gracefully handle NULL parent image device path
https://git.pengutronix.de/cgit/barebox/commit/?id=5cf1c8302cce (link may not be stable)
[4/4] fs: legacy: gracefully handle non existent files
https://git.pengutronix.de/cgit/barebox/commit/?id=2958ab65cfc6 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-06-13 7:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11 6:57 [PATCH master 1/4] efi: hide EFI related symbols when !EFI Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 2/4] lib: wchar: guard against NULL in strdup_wchar Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 3/4] efi: payload: gracefully handle NULL parent image device path Ahmad Fatoum
2024-06-11 6:57 ` [PATCH master 4/4] fs: legacy: gracefully handle non existent files Ahmad Fatoum
2024-06-13 7:30 ` [PATCH master 1/4] efi: hide EFI related symbols when !EFI Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox