From 5275028fd64287206294bcda324017be0555e956 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 4 Jul 2021 22:48:24 -0700 Subject: [PATCH] :bug: fixed user/admin filter std::string_view fuckery --- include/xxhash_str.h | 2 -- src/admin_filter.cpp | 2 ++ src/bank.cpp | 6 ++++-- src/user_filter.cpp | 4 ++++ src/xxhash_str.cpp | 11 ++--------- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/xxhash_str.h b/include/xxhash_str.h index 5e7cd31..61ec6bc 100644 --- a/include/xxhash_str.h +++ b/include/xxhash_str.h @@ -5,6 +5,4 @@ struct xxHashStringGen { XXH64_hash_t operator()(const std::string &str) const noexcept; - XXH64_hash_t operator()(std::string &&str) const noexcept; - XXH64_hash_t operator()(std::string_view str) const noexcept; }; diff --git a/src/admin_filter.cpp b/src/admin_filter.cpp index efc0084..14db1b2 100644 --- a/src/admin_filter.cpp +++ b/src/admin_filter.cpp @@ -20,9 +20,11 @@ void AdminFilter::doFilter(const HttpRequestPtr &req, std::size_t middle = results_view.find(':'); if (middle != std::string::npos) { + base64_result[middle] = '\0'; std::string_view username = results_view.substr(0, middle); if (bank.AdminVerifyAccount(username)) { + base64_result[new_sz] = '\0'; std::string_view password = results_view.substr(middle + 1); if (bank.VerifyPassword(username, password)) { diff --git a/src/bank.cpp b/src/bank.cpp index cabe485..96a9a66 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -129,7 +129,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam bool Bank::VerifyPassword(std::string_view name, std::string_view attempt) const noexcept { bool res = false; - users.if_contains(name.data(), [&res, &attempt](const User &u) { res = (u.password == xxHashStringGen{}(attempt)); }); + users.if_contains(name.data(), [&res, &attempt](const User &u) { res = (u.password == xxHashStringGen{}(attempt.data())); }); return res; } @@ -217,6 +217,8 @@ bool Bank::AdminVerifyAccount(std::string_view name) noexcept BankResponse Bank::AddUser(std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept { + std::cout << name << '\n' + << init_pass << '\n'; if (!ValidUsrname(name)) { return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"}; @@ -284,7 +286,7 @@ void Bank::Save() for (const auto &u : users) { //we know it contains this key but we call this func to grab mutex - users.if_contains(u.first, [&temp, &u](const User &u_val) { temp[u.first.data()] = u_val.Serialize(); }); + users.if_contains(u.first, [&temp, &u](const User &u_val) { temp[u.first] = u_val.Serialize(); }); } } if (temp.isNull()) diff --git a/src/user_filter.cpp b/src/user_filter.cpp index c6e6a58..68c5485 100644 --- a/src/user_filter.cpp +++ b/src/user_filter.cpp @@ -20,8 +20,12 @@ void UserFilter::doFilter(const HttpRequestPtr &req, std::size_t middle = results_view.find(':'); if (middle != std::string::npos) { + base64_result[middle] = '\0'; + base64_result[new_sz] = '\0'; + std::string_view username = results_view.substr(0, middle); std::string_view password = results_view.substr(middle + 1); + if (bank.VerifyPassword(username, password)) { fccb(); diff --git a/src/xxhash_str.cpp b/src/xxhash_str.cpp index abfb2cb..aeca738 100644 --- a/src/xxhash_str.cpp +++ b/src/xxhash_str.cpp @@ -1,14 +1,7 @@ #include "xxhash_str.h" +#include XXH64_hash_t xxHashStringGen::operator()(const std::string &str) const noexcept { return XXH3_64bits(str.data(), str.size()); -} -XXH64_hash_t xxHashStringGen::operator()(std::string &&str) const noexcept -{ - return XXH3_64bits(str.data(), str.size()); -} -XXH64_hash_t xxHashStringGen::operator()(std::string_view str) const noexcept -{ - return XXH3_64bits(str.data(), str.size()); -} +} \ No newline at end of file