diff --git a/winixd/core/misc.cpp b/winixd/core/misc.cpp index 7484b4b..fdae85a 100644 --- a/winixd/core/misc.cpp +++ b/winixd/core/misc.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2023, Tomasz Sowa + * Copyright (c) 2008-2024, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -820,25 +820,35 @@ return correct; bool ValidateEmail(const wchar_t * email) { - int at = 0; // how many '@' - int dots_after_at = 0; // how many dots in the domain part - + int at = 0; // how many '@' + int dots_after_at = 0; // how many dots in the domain part + const size_t address_max_length = 64; // the max length before a '@' + const size_t domain_max_length = 255; // the max length after a '@' + size_t address_length = 0; + size_t domain_length = 0; + for(size_t i=0 ; email[i] != 0 ; ++i) { if( !IsEmailCorrectChar(email[i]) ) return false; if( email[i] == '@' ) + { ++at; + } + else + { + if( at == 0 ) + address_length += 1; + else + domain_length += 1; - if( email[i] == '.' && at > 0 ) - ++dots_after_at; + if( email[i] == '.' && at > 0 ) + ++dots_after_at; + } } - if( at != 1 || dots_after_at == 0 ) - return false; - -return true; + return at == 1 && dots_after_at > 0 && address_length <= address_max_length && domain_length <= domain_max_length; }