mirror of
https://github.com/abraunegg/onedrive
synced 2026-03-14 14:35:46 +01:00
Update util.d
* add try block to ensure getPathOwnerMismatch() exception cannot cause application crash
This commit is contained in:
parent
91679c0b03
commit
ad7b4ba5f4
1 changed files with 24 additions and 12 deletions
38
src/util.d
38
src/util.d
|
|
@ -2127,22 +2127,34 @@ private bool getPathOwnerMismatch(string path, out uint fileUid, out uint effect
|
|||
version (Posix) {
|
||||
stat_t st;
|
||||
|
||||
// Ensure we pass a NUL-terminated string to the C API
|
||||
auto fullPath = absolutePath(path);
|
||||
const(char)* cpath = toStringz(fullPath);
|
||||
|
||||
if (lstat(cpath, &st) != 0) {
|
||||
if (debugLogging) {
|
||||
addLogEntry("getPathOwnerMismatch(): lstat() failed for '" ~ path ~ "'", ["debug"]);
|
||||
// Default outputs
|
||||
fileUid = 0;
|
||||
effectiveUid = cast(uint) geteuid();
|
||||
|
||||
try {
|
||||
// absolutePath can throw; keep this helper non-throwing
|
||||
auto fullPath = absolutePath(path);
|
||||
|
||||
// Ensure we pass a NUL-terminated string to the C API
|
||||
auto cpath = toStringz(fullPath);
|
||||
|
||||
if (lstat(cpath, &st) != 0) {
|
||||
if (debugLogging) {
|
||||
addLogEntry("getPathOwnerMismatch(): lstat() failed for '" ~ path ~ "'", ["debug"]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
fileUid = cast(uint) st.st_uid;
|
||||
// effectiveUid already set above
|
||||
return fileUid != effectiveUid;
|
||||
|
||||
} catch (Exception e) {
|
||||
if (debugLogging) {
|
||||
addLogEntry("getPathOwnerMismatch(): exception for '" ~ path ~ "': " ~ e.msg, ["debug"]);
|
||||
}
|
||||
fileUid = 0;
|
||||
effectiveUid = cast(uint) geteuid();
|
||||
return false;
|
||||
}
|
||||
|
||||
fileUid = cast(uint) st.st_uid;
|
||||
effectiveUid = cast(uint) geteuid();
|
||||
return fileUid != effectiveUid;
|
||||
} else {
|
||||
fileUid = 0;
|
||||
effectiveUid = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue