@@ -22,7 +22,7 @@ using namespace gromox;
2222
2323static BOOL cmdh_check_onlycmd (std::string_view cmd_line, smtp_context &);
2424
25- int cmdh_helo (std::string_view cmd_line, smtp_context &ctx)
25+ int cmdh_helo (std::string_view cmd_line, smtp_context &ctx) try
2626{
2727 auto pcontext = &ctx;
2828 int line_length = cmd_line.size ();
@@ -33,8 +33,8 @@ int cmdh_helo(std::string_view cmd_line, smtp_context &ctx)
3333 /* 502 Command not implemented */
3434 return 506 ;
3535 /* copy parameter to hello_domain */
36- strncpy (pcontext-> menv . hello_domain , & cmd_line[ 5 ], line_length - 5 );
37- pcontext->menv .hello_domain [line_length- 5 ] = ' \0 ' ;
36+ cmd_line. remove_prefix ( 5 );
37+ pcontext->menv .hello_domain = cmd_line ;
3838 } else if (line_length > 255 + 1 + 4 ) {
3939 /* domain name too long */
4040 return 502 ;
@@ -43,9 +43,11 @@ int cmdh_helo(std::string_view cmd_line, smtp_context &ctx)
4343 pcontext->menv .clear ();
4444 pcontext->last_cmd = T_HELO_CMD;
4545 return 205 ;
46- }
46+ } catch (const std::bad_alloc &) {
47+ return 416 ; /* ENOMEM */
48+ }
4749
48- static int cmdh_xhlo (std::string_view cmd_line, smtp_context &ctx)
50+ static int cmdh_xhlo (std::string_view cmd_line, smtp_context &ctx) try
4951{
5052 auto pcontext = &ctx;
5153 int line_length = cmd_line.size ();
@@ -58,8 +60,8 @@ static int cmdh_xhlo(std::string_view cmd_line, smtp_context &ctx)
5860 if (cmd_line[4 ] != ' ' )
5961 return 506 ;
6062 /* copy parameter to hello_domain */
61- strncpy (pcontext-> menv . hello_domain , & cmd_line[ 5 ], line_length - 5 );
62- pcontext->menv .hello_domain [line_length- 5 ] = ' \0 ' ;
63+ cmd_line. remove_prefix ( 5 );
64+ pcontext->menv .hello_domain = cmd_line ;
6365 } else if (line_length > 255 + 1 + 4 ) {
6466 /* domain name too long */
6567 return 202 ;
@@ -86,6 +88,8 @@ static int cmdh_xhlo(std::string_view cmd_line, smtp_context &ctx)
8688
8789 pcontext->connection .write (buff, string_length);
8890 return DISPATCH_CONTINUE;
91+ } catch (const std::bad_alloc &) {
92+ return 416 ; /* ENOMEM */
8993}
9094
9195int cmdh_lhlo (std::string_view cmd_line, smtp_context &ctx)
@@ -108,7 +112,7 @@ int cmdh_starttls(std::string_view cmd_line, smtp_context &ctx)
108112 if (!g_param.support_starttls )
109113 return 506 ;
110114 pcontext->last_cmd = T_STARTTLS_CMD;
111- memset ( pcontext->menv .hello_domain , ' \0 ' , std::size (pcontext-> menv . hello_domain ) );
115+ pcontext->menv .hello_domain . clear ( );
112116 pcontext->menv .clear ();
113117 return 210 ;
114118}
0 commit comments