Remove old string functions.

More specifically, this removes the functions:
strcasecmp_n
strchr_n
strrchr_n

and replaces the calls with the respective C-library calls that should
be part of just about all operating systems by now.
This commit is contained in:
Johanna Amann 2016-03-04 12:02:19 -08:00
parent 611a8ab935
commit 446a44787a
7 changed files with 11 additions and 51 deletions

View file

@ -54,7 +54,8 @@ void Finger_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig
if ( long_cnt )
line = skip_whitespace(line+2, end_of_line);
const char* at = strchr_n(line, end_of_line, '@');
assert(line <= end_of_line);
const char* at = reinterpret_cast<const char*>(memchr(line, '@', end_of_line - line));
const char* host = 0;
if ( ! at )
at = host = end_of_line;

View file

@ -1370,7 +1370,7 @@ void HTTP_Analyzer::HTTP_Request()
const char* method = (const char*) request_method->AsString()->Bytes();
int method_len = request_method->AsString()->Len();
if ( strcasecmp_n(method_len, method, "CONNECT") == 0 )
if ( strncasecmp(method, "CONNECT", method_len) == 0 )
connect_request = true;
if ( http_request )
@ -1564,7 +1564,7 @@ int HTTP_Analyzer::ExpectReplyMessageBody()
const BroString* method = UnansweredRequestMethod();
if ( method && strcasecmp_n(method->Len(), (const char*) (method->Bytes()), "HEAD") == 0 )
if ( method && strncasecmp((const char*) (method->Bytes()), "HEAD", method->Len()) == 0 )
return HTTP_BODY_NOT_EXPECTED;
if ( (reply_code >= 100 && reply_code < 200) ||

View file

@ -153,8 +153,9 @@ void Ident_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig)
else
{
const char* sys_type = line;
const char* colon = strchr_n(line, end_of_line, ':');
const char* comma = strchr_n(line, end_of_line, ',');
assert(line <= end_of_line);
const char* colon = reinterpret_cast<const char*>(memchr(line, ':', end_of_line - line));
const char* comma = reinterpret_cast<const char*>(memchr(line, ':', end_of_line - line));
if ( ! colon )
{
BadReply(length, orig_line);

View file

@ -148,7 +148,7 @@ void MIME_Mail::Undelivered(int len)
int strcasecmp_n(data_chunk_t s, const char* t)
{
return ::strcasecmp_n(s.length, s.data, t);
return strncasecmp(s.data, t, s.length);
}
int MIME_count_leading_lws(int len, const char* data)

View file

@ -809,7 +809,7 @@ void SMTP_Analyzer::ProcessExtension(int ext_len, const char* ext)
if ( ! ext )
return;
if ( ! strcasecmp_n(ext_len, ext, "PIPELINING") )
if ( ! strncasecmp(ext, "PIPELINING", ext_len) )
pipelining = 1;
}
@ -819,7 +819,7 @@ int SMTP_Analyzer::ParseCmd(int cmd_len, const char* cmd)
return -1;
for ( int code = SMTP_CMD_EHLO; code < SMTP_CMD_LAST; ++code )
if ( ! strcasecmp_n(cmd_len, cmd, smtp_cmd_word[code - SMTP_CMD_EHLO]) )
if ( ! strncasecmp(cmd, smtp_cmd_word[code - SMTP_CMD_EHLO], cmd_len) )
return code;
return -1;

View file

@ -323,24 +323,6 @@ string to_upper(const std::string& s)
return t;
}
const char* strchr_n(const char* s, const char* end_of_s, char ch)
{
for ( ; s < end_of_s; ++s )
if ( *s == ch )
return s;
return 0;
}
const char* strrchr_n(const char* s, const char* end_of_s, char ch)
{
for ( --end_of_s; end_of_s >= s; --end_of_s )
if ( *end_of_s == ch )
return end_of_s;
return 0;
}
int decode_hex(char ch)
{
if ( ch >= '0' && ch <= '9' )
@ -382,27 +364,6 @@ const char* strpbrk_n(size_t len, const char* s, const char* charset)
return 0;
}
int strcasecmp_n(int b_len, const char* b, const char* t)
{
if ( ! b )
return -1;
int i;
for ( i = 0; i < b_len; ++i )
{
char c1 = islower(b[i]) ? toupper(b[i]) : b[i];
char c2 = islower(t[i]) ? toupper(t[i]) : t[i];
if ( c1 < c2 )
return -1;
if ( c1 > c2 )
return 1;
}
return t[i] != '\0';
}
#ifndef HAVE_STRCASESTR
// This code is derived from software contributed to BSD by Chris Torek.
char* strcasestr(const char* s, const char* find)
@ -421,7 +382,7 @@ char* strcasestr(const char* s, const char* find)
if ( sc == 0 )
return 0;
} while ( char(tolower((unsigned char) sc)) != c );
} while ( strcasecmp_n(len, s, find) != 0 );
} while ( strncasecmp(s, find, len) != 0 );
--s;
}

View file

@ -143,11 +143,8 @@ extern char* get_word(char*& s);
extern void get_word(int length, const char* s, int& pwlen, const char*& pw);
extern void to_upper(char* s);
extern std::string to_upper(const std::string& s);
extern const char* strchr_n(const char* s, const char* end_of_s, char ch);
extern const char* strrchr_n(const char* s, const char* end_of_s, char ch);
extern int decode_hex(char ch);
extern unsigned char encode_hex(int h);
extern int strcasecmp_n(int s_len, const char* s, const char* t);
#ifndef HAVE_STRCASESTR
extern char* strcasestr(const char* s, const char* find);
#endif