Return values of chmod() and chown() in file_restore_metadata() are ignored #58

Closed
opened 2026-07-20 17:14:08 +02:00 by TapTap · 0 comments
Owner

Description

In src/shared/metadata.c lines 99-101, the return values of chmod() and chown() are ignored:

chmod(path, metadata->mode & 07777);
int chown_ret = chown(path, metadata->uid, metadata->gid);
(void)chown_ret;

The chmod() result is completely discarded, while chown() is stored in a variable that is immediately cast to void. This means permission/ownership restoration failures are silently ignored, and there is no way for the caller to know that metadata restoration failed.

Location

src/shared/metadata.c:99-101

Suggested Fix

Check the return values and log warnings on failure:

if (chmod(path, metadata->mode & 07777) != 0)
    log_message(LOG_LEVEL_WARNING, "Failed to restore permissions on %s", path);
if (chown(path, metadata->uid, metadata->gid) != 0)
    log_message(LOG_LEVEL_WARNING, "Failed to restore ownership on %s (may be expected if not root)", path);

Severity

Low

Category

Quality

## Description In `src/shared/metadata.c` lines 99-101, the return values of `chmod()` and `chown()` are ignored: ```c chmod(path, metadata->mode & 07777); int chown_ret = chown(path, metadata->uid, metadata->gid); (void)chown_ret; ``` The `chmod()` result is completely discarded, while `chown()` is stored in a variable that is immediately cast to void. This means permission/ownership restoration failures are silently ignored, and there is no way for the caller to know that metadata restoration failed. ## Location `src/shared/metadata.c:99-101` ## Suggested Fix Check the return values and log warnings on failure: ```c if (chmod(path, metadata->mode & 07777) != 0) log_message(LOG_LEVEL_WARNING, "Failed to restore permissions on %s", path); if (chown(path, metadata->uid, metadata->gid) != 0) log_message(LOG_LEVEL_WARNING, "Failed to restore ownership on %s (may be expected if not root)", path); ``` ## Severity Low ## Category Quality
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#58