Skip to content

Commit

Permalink
Fix an ancient memleak on %caps() parsing, add tests
Browse files Browse the repository at this point in the history
This leak has been there ever since rpm 4.7.0, so pretty close to 15
years. ASAN would've caught it, if it had it been tested. Oops.
Of course, in the fakechroot era we couldn't have tested installation
but we could've at least tested the parsing side.

Add tests for parsing, query and install functionality, and fix the
leak that is now very visible.
  • Loading branch information
pmatilai committed Apr 11, 2024
1 parent 1fe3e35 commit a385821
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ static void copyFileEntry(FileEntry src, FileEntry dest)
static void FileEntryFree(FileEntry entry)
{
argvFree(entry->langs);
free(entry->caps);
memset(entry, 0, sizeof(*entry));
}

Expand Down
25 changes: 25 additions & 0 deletions tests/data/SPECS/caps.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Name: caps
Version: 1.0
Release: 1
Summary: Test %caps
License: Public domain

%description
%{summary}

%prep
cat << EOF > test.c
int main(int argc, char *argv[])
{
return 0;
}
EOF

%build
gcc -o test test.c

%install
install -m 755 test -D ${RPM_BUILD_ROOT}/usr/bin/test

%files
%caps(cap_net_raw=p) /usr/bin/test
30 changes: 30 additions & 0 deletions tests/rpmbuild.at
Original file line number Diff line number Diff line change
Expand Up @@ -2995,3 +2995,33 @@ runroot rpmbuild --quiet -bb /data/SPECS/noperms.spec
[],
[])
RPMTEST_CLEANUP

AT_SETUP([rpmbuild %caps])
AT_KEYWORDS([build])
AT_SKIP_IF([$CAP_DISABLED])
RPMDB_INIT

RPMTEST_CHECK([
runroot rpmbuild --quiet -bb /data/SPECS/caps.spec
],
[0],
[],
[])

RPMTEST_CHECK([
runroot rpm -q --filecaps /build/RPMS/*/caps-1.0-1.*.rpm | grep -v build-id
],
[0],
[/usr/bin/test cap_net_raw=p
],
[])

RPMTEST_CHECK([
runroot rpm -U --nodeps /build/RPMS/*/caps-1.0-1.*.rpm
runroot_other /usr/sbin/getcap /usr/bin/test
],
[0],
[/usr/bin/test cap_net_raw=p]
[])

RPMTEST_CLEANUP

0 comments on commit a385821

Please sign in to comment.