Coverage Report

Created: 2026-04-29 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/dbus/qdbusutil_p.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// Copyright (C) 2016 Intel Corporation.
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:critical reason:data-parser
5
6
//
7
//  W A R N I N G
8
//  -------------
9
//
10
// This file is not part of the Qt API.  It exists for the convenience
11
// of the QLibrary class.  This header file may change from
12
// version to version without notice, or even be removed.
13
//
14
// We mean it.
15
//
16
17
#ifndef QDBUSUTIL_P_H
18
#define QDBUSUTIL_P_H
19
20
#include <QtDBus/private/qtdbusglobal_p.h>
21
#include <QtDBus/qdbuserror.h>
22
#include <QtCore/qstring.h>
23
#include <QtCore/qvariant.h>
24
25
#include "qdbus_symbols_p.h"
26
27
#ifndef QT_NO_DBUS
28
29
QT_BEGIN_NAMESPACE
30
31
#define Q_DBUS_NO_EXPORT        // force syncqt looking into this namespace
32
namespace Q_DBUS_NO_EXPORT QDBusUtil
33
{
34
    Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
35
36
    Q_DBUS_EXPORT bool isValidUniqueConnectionName(QStringView busName);
37
38
    Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
39
40
    Q_DBUS_EXPORT bool isValidMemberName(QStringView memberName);
41
42
    Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
43
44
    Q_DBUS_EXPORT bool isValidPartOfObjectPath(QStringView path);
45
46
    Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
47
48
    Q_DBUS_EXPORT bool isValidFixedType(int c);
49
50
    Q_DBUS_EXPORT bool isValidBasicType(int c);
51
52
    Q_DBUS_EXPORT bool isValidSignature(const QString &signature);
53
54
    Q_DBUS_EXPORT bool isValidSingleSignature(const QString &signature);
55
56
    Q_DBUS_EXPORT QString argumentToString(const QVariant &variant);
57
58
    enum AllowEmptyFlag {
59
        EmptyAllowed,
60
        EmptyNotAllowed
61
    };
62
63
    inline bool checkInterfaceName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
64
0
    {
65
0
        if (name.isEmpty()) {
66
0
            if (empty == EmptyAllowed) return true;
67
0
            *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Interface name cannot be empty"));
68
0
            return false;
69
0
        }
70
0
        if (isValidInterfaceName(name)) return true;
71
0
        *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Invalid interface class: %1").arg(name));
72
0
        return false;
73
0
    }
74
75
    inline bool checkBusName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
76
0
    {
77
0
        if (name.isEmpty()) {
78
0
            if (empty == EmptyAllowed) return true;
79
0
            *error = QDBusError(QDBusError::InvalidService, QLatin1StringView("Service name cannot be empty"));
80
0
            return false;
81
0
        }
82
0
        if (isValidBusName(name)) return true;
83
0
        *error = QDBusError(QDBusError::InvalidService, QLatin1StringView("Invalid service name: %1").arg(name));
84
0
        return false;
85
0
    }
86
87
    inline bool checkObjectPath(const QString &path, AllowEmptyFlag empty, QDBusError *error)
88
0
    {
89
0
        if (path.isEmpty()) {
90
0
            if (empty == EmptyAllowed) return true;
91
0
            *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1StringView("Object path cannot be empty"));
92
0
            return false;
93
0
        }
94
0
        if (isValidObjectPath(path)) return true;
95
0
        *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1StringView("Invalid object path: %1").arg(path));
96
0
        return false;
97
0
    }
98
99
    inline bool checkMemberName(const QString &name, AllowEmptyFlag empty, QDBusError *error, const char *nameType = nullptr)
100
0
    {
101
0
        if (!nameType) nameType = "member";
102
0
        if (name.isEmpty()) {
103
0
            if (empty == EmptyAllowed) return true;
104
0
            *error = QDBusError(QDBusError::InvalidMember, QLatin1StringView(nameType) + QLatin1StringView(" name cannot be empty"));
105
0
            return false;
106
0
        }
107
0
        if (isValidMemberName(name)) return true;
108
0
        *error = QDBusError(QDBusError::InvalidMember, QLatin1StringView("Invalid %1 name: %2")
109
0
                            .arg(QLatin1StringView(nameType), name));
110
0
        return false;
111
0
    }
112
113
    inline bool checkErrorName(const QString &name, AllowEmptyFlag empty, QDBusError *error)
114
0
    {
115
0
        if (name.isEmpty()) {
116
0
            if (empty == EmptyAllowed) return true;
117
0
            *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Error name cannot be empty"));
118
0
            return false;
119
0
        }
120
0
        if (isValidErrorName(name)) return true;
121
0
        *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Invalid error name: %1").arg(name));
122
0
        return false;
123
0
    }
124
125
    inline QString dbusService()
126
0
    { return QStringLiteral(DBUS_SERVICE_DBUS); }
127
    inline QString dbusPath()
128
0
    { return QStringLiteral(DBUS_PATH_DBUS); }
129
    inline QString dbusPathLocal()
130
0
    { return QStringLiteral(DBUS_PATH_LOCAL); }
131
    inline QString dbusInterface()
132
0
    {
133
        // it's the same string, but just be sure
134
0
        Q_ASSERT(dbusService() == QLatin1StringView(DBUS_INTERFACE_DBUS));
135
0
        return dbusService();
136
0
    }
137
    inline QString dbusInterfaceProperties()
138
0
    { return QStringLiteral(DBUS_INTERFACE_PROPERTIES); }
139
    inline QString dbusInterfaceIntrospectable()
140
0
    { return QStringLiteral(DBUS_INTERFACE_INTROSPECTABLE); }
141
    inline QString nameOwnerChanged()
142
0
    { return QStringLiteral("NameOwnerChanged"); }
143
    inline QString disconnectedErrorMessage()
144
0
    { return QStringLiteral("Not connected to D-Bus server"); }
145
}
146
147
QT_END_NAMESPACE
148
149
#endif // QT_NO_DBUS
150
#endif