Skip to content

Commit

Permalink
permissions: Gracefully handle malformed override files
Browse files Browse the repository at this point in the history
Override files aren't owned by Flatseal, therefore
there's no guarantees on its contents.

Closes #558
  • Loading branch information
tchx84 committed Aug 31, 2023
1 parent efbf39f commit d3dd2d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/models/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var FlatpakPermissionsModel = GObject.registerClass({
param_types: [GObject.TYPE_BOOLEAN, GObject.TYPE_BOOLEAN],
},
reset: {},
failed: {},
},
}, class FlatpakPermissionsModel extends GObject.Object {
_init() {
Expand Down Expand Up @@ -122,12 +123,19 @@ var FlatpakPermissionsModel = GObject.registerClass({
return GLib.build_filenamev([this._getBaseOverridesPath(), this._appId]);
}

static _loadPermissionsForPath(path, overrides, global) {
_loadPermissionsForPath(path, overrides, global) {
if (GLib.access(path, 0) !== 0)
return;

const keyFile = new GLib.KeyFile();
keyFile.load_from_file(path, 0);

try {
keyFile.load_from_file(path, 0);
} catch (err) {
logError(err, `Could not load ${path}`);
this.emit('failed');
return;
}

const [groups] = keyFile.get_groups();

Expand Down Expand Up @@ -178,20 +186,20 @@ var FlatpakPermissionsModel = GObject.registerClass({
if (isGlobalOverride(this._appId))
return;

this.constructor._loadPermissionsForPath(
this._loadPermissionsForPath(
this._applications.getMetadataPathForAppId(this._appId), false, false);
}

_loadGlobalOverrides() {
if (isGlobalOverride(this._appId))
return;

this.constructor._loadPermissionsForPath(
this._loadPermissionsForPath(
this._getGlobalOverridesPath(), true, true);
}

_loadOverrides() {
this.constructor._loadPermissionsForPath(
this._loadPermissionsForPath(
this._getOverridesPath(), true, false);
}

Expand Down
16 changes: 16 additions & 0 deletions src/widgets/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ var FlatsealWindow = GObject.registerClass({
this._toast.connect('button-clicked', this._undoReset.bind(this));
this._permissions.connect('reset', this._showToast.bind(this));

this._failedToast = new Adw.Toast();
this._failedToast.title = _('Could not load overrides');
this._failedToast.button_label = _('_Reset');
this._failedToast.timeout = null;
this._failedToast.connect('button-clicked', this._doReset.bind(this));
this._permissions.connect('failed', this._showFailedToast.bind(this));

this._contentLeaflet.bind_property(
'folded', this._backButton, 'visible', _bindReadFlags);

Expand Down Expand Up @@ -275,6 +282,7 @@ var FlatsealWindow = GObject.registerClass({
}

_updatePermissions() {
this._failedToast.dismiss();
const row = this._applicationsListBox.get_selected_row();
this._permissions.appId = row.appId;
this._permissionsTitle.title = row.appName;
Expand Down Expand Up @@ -339,6 +347,14 @@ var FlatsealWindow = GObject.registerClass({
this._toastOverlay.add_toast(this._toast);
}

_showFailedToast() {
this._toastOverlay.add_toast(this._failedToast);
}

_doReset() {
this._permissions.reset();
}

_undoReset() {
this._permissions.undo();
}
Expand Down

0 comments on commit d3dd2d6

Please sign in to comment.