Skip to content

Commit

Permalink
Add RPMERR_ILLEGAL_SYMLINK error code
Browse files Browse the repository at this point in the history
Give meaningful error message when encountering unsave symlinks.
  • Loading branch information
ffesti committed Jun 19, 2024
1 parent f3cf6ea commit 88649f3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/rpm/rpmarchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum rpmfilesErrorCodes {
RPMERR_EXIST_AS_DIR = -14,
RPMERR_INVALID_SYMLINK = -15,
RPMERR_ENOTDIR = -16,
RPMERR_ILLEGAL_SYMLINK = -17,

RPMERR_OPEN_FAILED = -32768,
RPMERR_CHMOD_FAILED = -32769,
Expand Down
3 changes: 2 additions & 1 deletion lib/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,17 @@ static int ensureDir(rpmPlugins plugins, const char *p, int owned, int create,
if (fd >= 0) {
dirfd = fd;
} else {
rc = RPMERR_OPEN_FAILED;
if (!quiet) {
if (errno == EPERM) {
rpmlog(RPMLOG_ERR, _("failed to open dir %s of %s: %s\n"),
bn, p, _("Unsave symlink"));
rc = RPMERR_ILLEGAL_SYMLINK;
} else {
rpmlog(RPMLOG_ERR, _("failed to open dir %s of %s: %s\n"),
bn, p, strerror(errno));
}
}
rc = RPMERR_OPEN_FAILED;
break;
}

Expand Down
1 change: 1 addition & 0 deletions lib/rpmfi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,7 @@ char * rpmfileStrerror(int rc)
case RPMERR_EXIST_AS_DIR:
s = _("File from package already exists as a directory in system");
break;
case RPMERR_ILLEGAL_SYMLINK: s = _("open failed - Unsave symlink"); break;
}

if (s != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion tests/rpmi.at
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ runroot --setenv SOURCE_DATE_EPOCH 1699955855 rpm -U /build/RPMS/noarch/replacet
[1],
[],
[error: failed to open dir opt of /opt/: Unsave symlink
error: unpacking of archive failed on file /opt/foo;6553448f: cpio: open failed - Operation not permitted
error: unpacking of archive failed on file /opt/foo;6553448f: cpio: open failed - Unsave symlink
error: replacetest-1.0-1.noarch: install failed
])
RPMTEST_CLEANUP

0 comments on commit 88649f3

Please sign in to comment.