summaryrefslogtreecommitdiff
path: root/xpcom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-11-19 20:11:34 +0000
committerMoonchild <moonchild@palemoon.org>2022-11-19 20:11:34 +0000
commitc127f58ef33bff7bbea7fb300bc858d9f8273aec (patch)
tree75272b6444fbf12a9c1e3c565d3f12a58e7a21d1 /xpcom
parent5e6006a2bd1f7ce9561c15b24f4afee9ae6aeb62 (diff)
downloaduxp-c127f58ef33bff7bbea7fb300bc858d9f8273aec.tar.gz
[XPCOM] Deal with lstat potentially lying in nsLocalFileUnix.
Diffstat (limited to 'xpcom')
-rw-r--r--xpcom/io/nsLocalFileUnix.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp
index 8aa5ae433b..a092d4c26a 100644
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -1720,11 +1720,14 @@ nsLocalFile::GetNativeTarget(nsACString& aResult)
return NS_ERROR_OUT_OF_MEMORY;
}
- if (readlink(mPath.get(), target, (size_t)size) < 0) {
+ ssize_t written = readlink(mPath.get(), target.BeginWriting(), size_t(size));
+ if (written < 0) {
free(target);
return NSRESULT_FOR_ERRNO();
}
- target[size] = '\0';
+ // Target might have changed since the lstat call, or lstat might lie, see bug
+ // 1791029.
+ target.Truncate(written);
nsresult rv = NS_OK;
nsCOMPtr<nsIFile> self(this);
@@ -1775,12 +1778,15 @@ nsLocalFile::GetNativeTarget(nsACString& aResult)
size = newSize;
}
- int32_t linkLen = readlink(flatRetval.get(), target, size);
+ ssize_t linkLen = readlink(flatRetval.get(), target, size);
if (linkLen == -1) {
rv = NSRESULT_FOR_ERRNO();
break;
}
- target[linkLen] = '\0';
+ // Target might have changed since the lstat call, or lstat might lie, see bug
+ // 1791029.
+ newTarget.Truncate(linkLen);
+ target = newTarget;
}
free(target);