Files
collabora-code-docker/code-loongarch.patch
2025-05-06 11:41:22 +08:00

64 lines
2.9 KiB
Diff

diff --git a/common/FileUtil.cpp b/common/FileUtil.cpp
index ebd0e13..c4f29bb 100644
--- a/common/FileUtil.cpp
+++ b/common/FileUtil.cpp
@@ -769,11 +769,11 @@ namespace FileUtil
std::string fullpath(path);
fullpath.append("/").append(entry._name);
- const std::size_t size = entry._size;
- std::vector<char> target(size + 1);
+ constexpr std::size_t MAX_SYMLINK_SIZE = PATH_MAX;
+ std::vector<char> target(MAX_SYMLINK_SIZE + 1);
char* target_data = target.data();
- const ssize_t read = readlink(fullpath.c_str(), target_data, size);
- if (read <= 0 || static_cast<std::size_t>(read) > size)
+ const ssize_t read = readlink(fullpath.c_str(), target_data, MAX_SYMLINK_SIZE);
+ if (read <= 0 || static_cast<std::size_t>(read) > MAX_SYMLINK_SIZE)
std::cerr << "lslr: fail to read: " << fullpath << " error: " << std::strerror(errno) << std::endl;
else
{
diff --git a/common/Seccomp.cpp b/common/Seccomp.cpp
index 636b313..b45a6b0 100644
--- a/common/Seccomp.cpp
+++ b/common/Seccomp.cpp
@@ -61,6 +61,10 @@
# define AUDIT_ARCH_NR AUDIT_ARCH_PPC64
# define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.regs->gpr[_reg])
# define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, 0)
+#elif defined(__loongarch__)
+# define AUDIT_ARCH_NR AUDIT_ARCH_LOONGARCH64
+# define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.__gregs[_reg])
+# define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, 11)
#else
# error "Platform does not support seccomp filtering yet - unsafe."
#endif
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 0169fd2..d9fc111 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -477,6 +477,7 @@ namespace
int typeflag,
struct FTW* /*ftwbuf*/)
{
+ (void)sb;
if (strcmp(fpath, sourceForLinkOrCopy.c_str()) == 0)
{
LOG_TRC("nftw: Skipping redundant path: " << fpath);
@@ -536,11 +537,11 @@ namespace
break;
case FTW_SL:
{
- const std::size_t size = sb->st_size;
- std::vector<char> target(size + 1);
+ constexpr std::size_t MAX_SYMLINK_SIZE = PATH_MAX;
+ std::vector<char> target(MAX_SYMLINK_SIZE + 1);
char* target_data = target.data();
- const ssize_t written = readlink(fpath, target_data, size);
- if (written <= 0 || static_cast<std::size_t>(written) > size)
+ const ssize_t written = readlink(fpath, target_data, MAX_SYMLINK_SIZE);
+ if (written <= 0 || static_cast<std::size_t>(written) > MAX_SYMLINK_SIZE)
{
LOG_SYS("nftw: readlink(\"" << fpath << "\") failed");
Util::forcedExit(EX_SOFTWARE);