[PATCH 15/44] param: handle NULL gracefully in bobject_get_param
Ahmad Fatoum
a.fatoum at barebox.org
Mon Aug 11 05:27:55 PDT 2025
This allows using bobject_get_param with non-existent parameter names
without risking a crash inside bobject_get_param().
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
lib/parameter.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/parameter.c b/lib/parameter.c
index 73cc3701b938..0f9164386c6d 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -71,8 +71,14 @@ struct param_d *get_param_by_name(bobject_t _bobj, const char *name)
const char *bobject_get_param(bobject_t _bobj, const char *name)
{
struct bobject *bobj = _bobj.bobj;
- struct param_d *param = get_param_by_name(bobj, name);
+ struct param_d *param;
+ if (!bobj) {
+ errno = ENODEV;
+ return NULL;
+ }
+
+ param = get_param_by_name(bobj, name);
if (!param) {
errno = EINVAL;
return NULL;
--
2.39.5
More information about the barebox
mailing list