Check for valid QAccessibleInterface before invoking action

To avoid illegal access, the change ensures that the QAccessibleInterface
is non-null and valid before accessing its QAccessibleActionInterface.

The check for the validity was also added to existing code which
previously only checked for the QAccessibleInterface not being null.

Fixes: QTBUG-132059
Change-Id: I69fc4f9bb052ded8f188032d324666d0c00b9c3c
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Lars Schmertmann <lars.schmertmann@governikus.de>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 279c891ddf0ad10dd86c8fc836ce385df57593c4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit a30613197731cd77dd4dac8e3d7d8205718c37f0)
This commit is contained in:
Jan Moeller 2024-12-09 16:13:08 +01:00 committed by Qt Cherry-pick Bot
parent d89bc3c7aa
commit d4e2c76ae8

View File

@ -70,7 +70,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (NSString*)accessibilityLabel - (NSString*)accessibilityLabel
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface) { if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid; qWarning() << "invalid accessible interface for: " << self.axid;
return @""; return @"";
} }
@ -82,7 +82,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (NSString*)accessibilityIdentifier - (NSString*)accessibilityIdentifier
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface) { if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid; qWarning() << "invalid accessible interface for: " << self.axid;
return @""; return @"";
} }
@ -92,7 +92,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (NSString*)accessibilityHint - (NSString*)accessibilityHint
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface) { if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid; qWarning() << "invalid accessible interface for: " << self.axid;
return @""; return @"";
} }
@ -102,7 +102,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (NSString*)accessibilityValue - (NSString*)accessibilityValue
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface) { if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid; qWarning() << "invalid accessible interface for: " << self.axid;
return @""; return @"";
} }
@ -127,7 +127,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (CGRect)accessibilityFrame - (CGRect)accessibilityFrame
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface) { if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid; qWarning() << "invalid accessible interface for: " << self.axid;
return CGRect(); return CGRect();
} }
@ -141,7 +141,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
UIAccessibilityTraits traits = UIAccessibilityTraitNone; UIAccessibilityTraits traits = UIAccessibilityTraitNone;
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface) { if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid; qWarning() << "invalid accessible interface for: " << self.axid;
return traits; return traits;
} }
@ -183,6 +183,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (BOOL)accessibilityActivate - (BOOL)accessibilityActivate
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid;
return NO;
}
if (QAccessibleActionInterface *action = iface->actionInterface()) { if (QAccessibleActionInterface *action = iface->actionInterface()) {
if (action->actionNames().contains(QAccessibleActionInterface::pressAction())) { if (action->actionNames().contains(QAccessibleActionInterface::pressAction())) {
action->doAction(QAccessibleActionInterface::pressAction()); action->doAction(QAccessibleActionInterface::pressAction());
@ -198,6 +203,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (void)accessibilityIncrement - (void)accessibilityIncrement
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid;
return;
}
if (QAccessibleActionInterface *action = iface->actionInterface()) if (QAccessibleActionInterface *action = iface->actionInterface())
action->doAction(QAccessibleActionInterface::increaseAction()); action->doAction(QAccessibleActionInterface::increaseAction());
} }
@ -205,6 +215,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (void)accessibilityDecrement - (void)accessibilityDecrement
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid;
return;
}
if (QAccessibleActionInterface *action = iface->actionInterface()) if (QAccessibleActionInterface *action = iface->actionInterface())
action->doAction(QAccessibleActionInterface::decreaseAction()); action->doAction(QAccessibleActionInterface::decreaseAction());
} }
@ -212,6 +227,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAccessibilityElement);
- (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction - (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction
{ {
QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid); QAccessibleInterface *iface = QAccessible::accessibleInterface(self.axid);
if (!iface || !iface->isValid()) {
qWarning() << "invalid accessible interface for: " << self.axid;
return NO;
}
QAccessibleActionInterface *action = iface->actionInterface(); QAccessibleActionInterface *action = iface->actionInterface();
if (!action) if (!action)
return NO; return NO;