Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c581f4f5 authored by jiabin's avatar jiabin Committed by Automerger Merge Worker
Browse files

Do not log sensitive information. am: 827df1b7 am: 8d822819 am: 478a0f32

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/12276952

Change-Id: If8627b9da11a0b4f649709c50049a86185076d48
parents 6af7e11e 478a0f32
Loading
Loading
Loading
Loading
+41 −2
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
#include <media/DeviceDescriptorBase.h>
#include <media/TypeConverter.h>

#include <arpa/inet.h>
#include <regex>

namespace android {

DeviceDescriptorBase::DeviceDescriptorBase(audio_devices_t type) :
@@ -34,6 +37,31 @@ DeviceDescriptorBase::DeviceDescriptorBase(audio_devices_t type, const std::stri
{
}

namespace {

static const std::string SUPPRESSED = "SUPPRESSED";
static const std::regex MAC_ADDRESS_REGEX("([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}");

bool isAddressSensitive(const std::string &address) {
    if (std::regex_match(address, MAC_ADDRESS_REGEX)) {
        return true;
    }

    sockaddr_storage ss4;
    if (inet_pton(AF_INET, address.c_str(), &ss4) > 0) {
        return true;
    }

    sockaddr_storage ss6;
    if (inet_pton(AF_INET6, address.c_str(), &ss6) > 0) {
        return true;
    }

    return false;
}

} // namespace

DeviceDescriptorBase::DeviceDescriptorBase(const AudioDeviceTypeAddr &deviceTypeAddr) :
        AudioPort("", AUDIO_PORT_TYPE_DEVICE,
                  audio_is_output_device(deviceTypeAddr.mType) ? AUDIO_PORT_ROLE_SINK :
@@ -43,6 +71,12 @@ DeviceDescriptorBase::DeviceDescriptorBase(const AudioDeviceTypeAddr &deviceType
    if (mDeviceTypeAddr.mAddress.empty() && audio_is_remote_submix_device(mDeviceTypeAddr.mType)) {
        mDeviceTypeAddr.mAddress = "0";
    }
    mIsAddressSensitive = isAddressSensitive(mDeviceTypeAddr.mAddress);
}

void DeviceDescriptorBase::setAddress(const std::string &address) {
    mDeviceTypeAddr.mAddress = address;
    mIsAddressSensitive = isAddressSensitive(address);
}

void DeviceDescriptorBase::toAudioPortConfig(struct audio_port_config *dstConfig,
@@ -130,10 +164,15 @@ void DeviceDescriptorBase::dump(std::string *dst, int spaces, int index,
    AudioPort::dump(dst, spaces, verbose);
}

std::string DeviceDescriptorBase::toString() const
std::string DeviceDescriptorBase::toString(bool includeSensitiveInfo) const
{
    std::stringstream sstream;
    sstream << "type:0x" << std::hex << type() << ",@:" << mDeviceTypeAddr.mAddress;
    sstream << "type:0x" << std::hex << type();
    // IP and MAC address are sensitive information. The sensitive information will be suppressed
    // is `includeSensitiveInfo` is false.
    sstream << ",@:"
            << (!includeSensitiveInfo && mIsAddressSensitive ? SUPPRESSED
                                                             : mDeviceTypeAddr.mAddress);
    return sstream.str();
}

+10 −2
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public:

    audio_devices_t type() const { return mDeviceTypeAddr.mType; }
    std::string address() const { return mDeviceTypeAddr.mAddress; }
    void setAddress(const std::string &address) { mDeviceTypeAddr.mAddress = address; }
    void setAddress(const std::string &address);
    const AudioDeviceTypeAddr& getDeviceTypeAddr() const { return mDeviceTypeAddr; }

    // AudioPortConfig
@@ -61,7 +61,14 @@ public:
    void dump(std::string *dst, int spaces, int index,
              const char* extraInfo = nullptr, bool verbose = true) const;
    void log() const;
    std::string toString() const;

    /**
     * Return a string to describe the DeviceDescriptor.
     *
     * @param includeSensitiveInfo sensitive information will be added when it is true.
     * @return a string that can be used to describe the DeviceDescriptor.
     */
    std::string toString(bool includeSensitiveInfo = false) const;

    bool equals(const sp<DeviceDescriptorBase>& other) const;

@@ -70,6 +77,7 @@ public:

protected:
    AudioDeviceTypeAddr mDeviceTypeAddr;
    bool mIsAddressSensitive;
    uint32_t mEncapsulationModes = 0;
    uint32_t mEncapsulationMetadataTypes = 0;
};
+3 −1
Original line number Diff line number Diff line
@@ -248,7 +248,9 @@ public:
        return String8("");
    }

    std::string toString() const;
    // Return a string to describe the DeviceVector. The sensitive information will only be
    // added to the string if `includeSensitiveInfo` is true.
    std::string toString(bool includeSensitiveInfo = false) const;

    void dump(String8 *dst, const String8 &tag, int spaces = 0, bool verbose = true) const;

+1 −1
Original line number Diff line number Diff line
@@ -516,7 +516,7 @@ void AudioInputDescriptor::dump(String8 *dst) const
    dst->appendFormat(" Sampling rate: %d\n", mSamplingRate);
    dst->appendFormat(" Format: %d\n", mFormat);
    dst->appendFormat(" Channels: %08x\n", mChannelMask);
    dst->appendFormat(" Devices %s\n", mDevice->toString().c_str());
    dst->appendFormat(" Devices %s\n", mDevice->toString(true /*includeSensitiveInfo*/).c_str());
    mEnabledEffects.dump(dst, 1 /*spaces*/, false /*verbose*/);
    dst->append(" AudioRecord Clients:\n");
    ClientMapHandler<RecordClientDescriptor>::dump(dst);
+1 −1
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ void AudioOutputDescriptor::dump(String8 *dst) const
    dst->appendFormat(" Sampling rate: %d\n", mSamplingRate);
    dst->appendFormat(" Format: %08x\n", mFormat);
    dst->appendFormat(" Channels: %08x\n", mChannelMask);
    dst->appendFormat(" Devices: %s\n", devices().toString().c_str());
    dst->appendFormat(" Devices: %s\n", devices().toString(true /*includeSensitiveInfo*/).c_str());
    dst->appendFormat(" Global active count: %u\n", mGlobalActiveCount);
    for (const auto &iter : mRoutingActivities) {
        dst->appendFormat(" Product Strategy id: %d", iter.first);
Loading