代码拉取完成,页面将自动刷新
From fcb83efb61c7898fa2ef20e010bf760278ec6746 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Thu, 29 Feb 2024 20:43:35 +0100
Subject: [PATCH] lslocks: fix buffer overflow
* don't use memset() to init variables
* use xreaddir() to reduce code
* use ssize_t for readlinkat() return value to avoid buffer overflow
Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit f030775ffeaa8627c88434f7d0cba1a454aa0ffa)
Reference:https://github.com/util-linux/util-linux/commit/fcb83efb61c7898fa2ef20e010bf760278ec6746
Conflict:context adapt
---
misc-utils/lslocks.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c
index caca13f..a2d634a 100644
--- a/misc-utils/lslocks.c
+++ b/misc-utils/lslocks.c
@@ -45,6 +45,7 @@
#include "closestream.h"
#include "optutils.h"
#include "procfs.h"
+#include "fileutils.h"
/* column IDs */
enum {
@@ -170,13 +171,12 @@ static char *get_filename_sz(ino_t inode, pid_t lock_pid, size_t *size)
struct stat sb;
struct dirent *dp;
DIR *dirp;
- size_t len;
+ size_t sz;
int fd;
- char path[PATH_MAX], sym[PATH_MAX], *ret = NULL;
+ char path[PATH_MAX] = { 0 },
+ sym[PATH_MAX] = { 0 }, *ret = NULL;
*size = 0;
- memset(path, 0, sizeof(path));
- memset(sym, 0, sizeof(sym));
/*
* We know the pid so we don't have to
@@ -187,16 +187,14 @@ static char *get_filename_sz(ino_t inode, pid_t lock_pid, size_t *size)
if (!(dirp = opendir(path)))
return NULL;
- if ((len = strlen(path)) >= (sizeof(path) - 2))
+ if ((sz = strlen(path)) >= (sizeof(path) - 2))
goto out;
if ((fd = dirfd(dirp)) < 0 )
goto out;
- while ((dp = readdir(dirp))) {
- if (!strcmp(dp->d_name, ".") ||
- !strcmp(dp->d_name, ".."))
- continue;
+ while ((dp = xreaddir(dirp))) {
+ ssize_t len;
errno = 0;
--
2.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。