diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-07-11 19:53:29 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-12 23:11:35 +0200 |
commit | c70f45ff4498fcb7ce0671e9107ecff8009d7eb2 (patch) | |
tree | 6250cc4ba6c43ed57639f3d7ff9c5fd34800989f /Userland/Services/DHCPClient | |
parent | e3da0adfe6d278424970dad5a642bda650737e42 (diff) | |
download | serenity-c70f45ff4498fcb7ce0671e9107ecff8009d7eb2.zip |
Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the
StringView users. This is an important step towards the goal of removing
StringView(char const*), as it moves the responsibility of calculating
the size of the string to the user of the StringView (which will prevent
naive uses causing OOB access).
Diffstat (limited to 'Userland/Services/DHCPClient')
-rw-r--r-- | Userland/Services/DHCPClient/DHCPv4.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Userland/Services/DHCPClient/DHCPv4.h b/Userland/Services/DHCPClient/DHCPv4.h index de00f46c6d..762bc2b345 100644 --- a/Userland/Services/DHCPClient/DHCPv4.h +++ b/Userland/Services/DHCPClient/DHCPv4.h @@ -214,8 +214,17 @@ public: MACAddress const& chaddr() const { return *(MACAddress const*)&m_chaddr[0]; } void set_chaddr(MACAddress const& mac) { *(MACAddress*)&m_chaddr[0] = mac; } - StringView sname() const { return { (char const*)&m_sname[0] }; } - StringView file() const { return { (char const*)&m_file[0] }; } + StringView sname() const + { + char const* sname_ptr = reinterpret_cast<char const*>(&m_sname[0]); + return { sname_ptr, strlen(sname_ptr) }; + } + + StringView file() const + { + char const* file_ptr = reinterpret_cast<char const*>(&m_file[0]); + return { file_ptr, strlen(file_ptr) }; + } private: NetworkOrdered<u8> m_op; |