Do all session name validation in session_path().

This commit is contained in:
Tim Allen 2022-04-07 21:23:10 +10:00
parent eae8ea8a54
commit 9e6b678cf7

View File

@ -605,8 +605,8 @@ const String& session_directory()
String session_path(StringView session)
{
if (contains(session, '/'))
throw runtime_error{"session names cannot have slashes"};
if (not all_of(session, is_identifier))
throw runtime_error{format("invalid session name: '{}'", session)};
return format("{}/{}", session_directory(), session);
}
@ -848,9 +848,6 @@ private:
Server::Server(String session_name, bool is_daemon)
: m_session{std::move(session_name)}, m_is_daemon{is_daemon}
{
if (not all_of(m_session, is_identifier))
throw runtime_error{format("invalid session name: '{}'", m_session)};
int listen_sock = socket(AF_UNIX, SOCK_STREAM, 0);
fcntl(listen_sock, F_SETFD, FD_CLOEXEC);
sockaddr_un addr = session_addr(m_session);
@ -885,9 +882,6 @@ Server::Server(String session_name, bool is_daemon)
bool Server::rename_session(StringView name)
{
if (not all_of(name, is_identifier))
throw runtime_error{format("invalid session name: '{}'", name)};
String old_socket_file = session_path(m_session);
String new_socket_file = session_path(name);