New style hook support not robust on removal

Bug #1776218 reported by Michael Vogt on 2018-06-11
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apt (Ubuntu)
High
Julian Andres Klode
Bionic
Undecided
Unassigned

Bug Description

[Impact]
The new style (json-rpc) hooks are great. However when using them in snapd we noticed the following problem. When shipping a hook in /etc/apt/apt.conf.d/20snapd.conf like:
```
AptCli::Hooks::Install { "[ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt || true"; };
```
this works fine.

However when the snapd package is removed apt fails with:
```
...
Purging configuration files for snapd (1337.2.32.8) ...
Final directory cleanup
Discarding preserved snap namespaces
Removing extra snap-confine apparmor rules
Removing snapd cache
Removing snapd state

E: Could not read response to hello message from hook [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt || true: Connection reset by peer
E: Could not read message separator line after handshake from [ ! -f /usr/bin/snap ] || /usr/bin/snap advise-snap --from-apt || true: Connection reset by peer
quiet: end of output.
```

I.e. if the hook is not there apt still expectes a handshake.

[Test case]
cat > rootdir/etc/apt/apt.conf.d/99-json-hooks << EOF
       AptCli::Hooks::Install:: "true";
       AptCli::Hooks::Search:: "true";
EOF
and run an install.

This test and some more error handling tests are part of the test suite, too, so autopkgtest covers that for us.

[Regression potential]
Hooks that do not respond to the initial handshake and just exit with 0 are silently ignored.

[Other info]
There are some more changes in the patch that fix other cases of error handling: As can be seen above, there are 2 error messages for one error, because the code did not abort early, but tried to carry on, reading more data. It now goes directly to the end.

Michael Vogt (mvo) wrote :

Any chance this can be fixed for 18.04.1 ?

Changed in apt (Ubuntu):
status: New → In Progress
importance: Undecided → High
assignee: nobody → Julian Andres Klode (juliank)
tags: added: id-5b333ce4c9e5f90176d2242c
description: updated
Changed in apt (Ubuntu):
status: In Progress → Fix Committed
Julian Andres Klode (juliank) wrote :

1.6.3 is in unapproved queue for bionic

Changed in apt (Ubuntu Bionic):
status: New → In Progress
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.7.0~alpha2

---------------
apt (1.7.0~alpha2) experimental; urgency=medium

  * Handle JSON hooks that just close the file/exit and fix some other errors
    (LP: #1776218)
  * Use cheaper entropy source for randomizing items to fetch

 -- Julian Andres Klode <email address hidden> Mon, 09 Jul 2018 16:02:45 +0200

Changed in apt (Ubuntu):
status: Fix Committed → Fix Released

Hello Michael, or anyone else affected,

Accepted apt into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/apt/1.6.3 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed.Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in apt (Ubuntu Bionic):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-bionic
Julian Andres Klode (juliank) wrote :

autopkgtest has run the tests for us, and passed for 1.6.3, so it's verified.

tags: added: verification-done verification-done-bionic
removed: verification-needed verification-needed-bionic
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 1.6.3

---------------
apt (1.6.3) unstable; urgency=medium

  * Handle JSON hooks that just close the file/exit and fix some other errors
    (LP: #1776218)

 -- Julian Andres Klode <email address hidden> Mon, 09 Jul 2018 16:41:27 +0200

Changed in apt (Ubuntu Bionic):
status: Fix Committed → Fix Released

The verification of the Stable Release Update for apt has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers