libuio: fix FILE descriptor leak
PATCH 1/1 libuio: fix FILE descriptor leak
The function uio_line_from_file() fails to close the FILE pointer when fgets() returns NULL, causing a file descriptor leak.
This can be triggered when reading from /sys files that return empty content, leading to resource exhaustion over time.
Fix this by using goto-based error handling to ensure fclose() is called on all exit paths.
--- ...ix-fclose-leak-in-uio_line_from_file.patch | 31 +++++++++++++++++++ .../libuio/libuio_0.2.1.bbappend | 3 ++ 2 files changed, 34 insertions(+) create mode 100644 meta-oe/recipes-extended/libuio/libuio/fix-fclose-leak-in-uio_line_from_file.patch create mode 100644 meta-oe/recipes-extended/libuio/libuio_0.2.1.bbappend
meta-oe/recipes-extended/libuio/libuio/fix-fclose-leak-in-uio_line_from_file.patch new file +31 -0
@@ -0,0 +1,31 @@ +From: Qliangw <[email protected]> +Subject: [PATCH] Fix FILE descriptor leak in uio_line_from_file() + +The function uio_line_from_file() fails to close the FILE pointer +when fgets() returns NULL, causing a file descriptor leak. + +Upstream-Status: Pending +Signed-off-by: Qliangw <[email protected]> + +--- a/src/uio_line_from_file.c ++++ b/src/uio_line_from_file.c +@@ -28,14 +28,17 @@ + { + char *s; + int i; ++ int ret = 0; + memset(linebuf, 0, UIO_MAX_NAME_SIZE); + FILE* file = fopen(filename,"r"); + if (!file) return -1; + s = fgets(linebuf,UIO_MAX_NAME_SIZE,file); +- if (!s) return -2; ++ if (!s) { ret = -2; goto out; } + for (i=0; (*s)&&(i<UIO_MAX_NAME_SIZE); i++) { + if (*s == '\n') *s = 0; + s++; + } +- return 0; ++out: ++ fclose(file); ++ return ret; + }
meta-oe/recipes-extended/libuio/libuio_0.2.1.bbappend new file +3 -0
@@ -0,0 +1,3 @@ +FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" + +SRC_URI += "file://fix-fclose-leak-in-uio_line_from_file.patch"
Signature · 1 line
2.53.0.windows.2
Quoted 24 lines · Qliangw via lists.openembedded.org
The function
uio_line_from_file()fails to close the FILE pointer whenfgets()returns NULL, causing a file descriptor leak.This can be triggered when reading from /sys files that return empty content, leading to resource exhaustion over time.
Fix this by using goto-based error handling to ensure
fclose()is called on all exit paths.Signed-off-by Qliangw <[email protected]>--- ...ix-fclose-leak-in-uio_line_from_file.patch | 31 +++++++++++++++++++ .../libuio/libuio_0.2.1.bbappend | 3 ++ 2 files changed, 34 insertions(+) create mode 100644 meta-oe/recipes-extended/libuio/libuio/fix-fclose-leak-in-uio_line_from_file.patch create mode 100644 meta-oe/recipes-extended/libuio/libuio_0.2.1.bbappendmeta-oe/recipes-extended/libuio/libuio/fix-fclose-leak-in-uio_line_from_file.patch new file +0
-0
meta-oe/recipes-extended/libuio/libuio/fix-fclose-leak-in-uio_line_from_file.patch line 7
Quoted 7 lines
meta-oe/recipes-extended/libuio/libuio/fix-fclose-leak-in-uio_line_from_file.patch new file +7
-0@@ -0,0 +1,31 @@ +From: Qliangw <[email protected]> +Subject: [PATCH] Fix FILE descriptor leak in uio_line_from_file() + +The function uio_line_from_file() fails to close the FILE pointer +when fgets() returns NULL, causing a file descriptor leak. + +Upstream-Status: Pending
As per[1], this status is an exception. Please include valid justification for it.
meta-oe/recipes-extended/libuio/libuio_0.2.1.bbappend
Quoted 25 lines
meta-oe/recipes-extended/libuio/libuio/fix-fclose-leak-in-uio_line_from_file.patch new file +24
-0+Signed-off-by: Qliangw <[email protected]> + +--- a/src/uio_line_from_file.c ++++ b/src/uio_line_from_file.c +@@ -28,14 +28,17 @@ + { + char *s; + int i; ++ int ret = 0; + memset(linebuf, 0, UIO_MAX_NAME_SIZE); + FILE* file = fopen(filename,"r"); + if (!file) return -1; + s = fgets(linebuf,UIO_MAX_NAME_SIZE,file); +- if (!s) return -2; ++ if (!s) { ret = -2; goto out; } + for (i=0; (*s)&&(i<UIO_MAX_NAME_SIZE); i++) { + if (*s == '\n') *s = 0; + s++; + } +- return 0; ++out: ++ fclose(file); ++ return ret; + }meta-oe/recipes-extended/libuio/libuio_0.2.1.bbappend +0
-0
No need to add bbappend file, simply update SRC_URI in libuio_0.2.1bb recipe file
Quoted 20 lines
new file mode 100644
index 0000000000..d0e0dbb9a8meta-oe/recipes-extended/libuio/libuio_0.2.1.bbappend new file +3
-1@@ -0,0 +1,3 @@ +FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" + +SRC_URI += "file://fix-fclose-leak-in-uio_line_from_file.patch" --2.53.0.windows.2
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#127271): https://lists.openembedded.org/g/openembedded-devel/message/127271
Mute This Topic: https://lists.openembedded.org/mt/119525599/3619737
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-