diff options
| author | Heinrich Schuchardt <[email protected]> | 2023-09-29 02:47:17 +0200 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2023-10-09 15:24:31 -0400 |
| commit | 6da11cc81ea773d9a1e3059da311c6f2e2aeb6ef (patch) | |
| tree | f263b4f7a655ae63af68784be4dd834858a8095c /common/stdio.c | |
| parent | 6a1e0ae43e2108a88e022103b3b303c9f4964a64 (diff) | |
stdio: fix stdio_deregister_dev()
When copying the name of a stdio device we must ensure that it is NUL
terminated before passing it to strcmp() to avoid a buffer overrun.
Truncating the name field leads to failure to deregister a stdio device.
When copying we must ensure that the name field sizes match.
Addresses-Coverity-ID: 350462 String not null terminated
Fixes: 5294e97832a6 ("stdio: extend "name" to 32 symbols")
Signed-off-by: Heinrich Schuchardt <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
Diffstat (limited to 'common/stdio.c')
| -rw-r--r-- | common/stdio.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/common/stdio.c b/common/stdio.c index 010bf576af0..e3354f092dc 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -259,7 +259,7 @@ int stdio_register(struct stdio_dev *dev) int stdio_deregister_dev(struct stdio_dev *dev, int force) { struct list_head *pos; - char temp_names[3][16]; + char temp_names[3][STDIO_NAME_LEN]; int i; /* get stdio devices (ListRemoveItem changes the dev list) */ @@ -272,8 +272,8 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force) /* Device is assigned -> report error */ return -EBUSY; } - memcpy(&temp_names[i][0], stdio_devices[i]->name, - sizeof(temp_names[i])); + strlcpy(&temp_names[i][0], stdio_devices[i]->name, + sizeof(temp_names[i])); } list_del(&dev->list); |
