@@ -214,7 +214,7 @@ std::string PassiveDNSPlugin::get_name(const char *data) const
214214 data += ((uint8_t ) data[0 ] + 1 );
215215 }
216216
217- if (name[0 ] == ' .' ) {
217+ if (name. length () > 0 && name [0 ] == ' .' ) {
218218 name.erase (0 , 1 );
219219 }
220220
@@ -433,7 +433,7 @@ bool PassiveDNSPlugin::process_ptr_record(std::string name, RecordExtPassiveDNS
433433{
434434 memset (&rec->ip , 0 , sizeof (rec->ip ));
435435
436- if (name[name.length () - 1 ] == ' .' ) {
436+ if (name. length () > 0 && name [name.length () - 1 ] == ' .' ) {
437437 name.erase (name.length () - 1 );
438438 }
439439
@@ -446,7 +446,7 @@ bool PassiveDNSPlugin::process_ptr_record(std::string name, RecordExtPassiveDNS
446446 size_t type_pos = name.find (type_str);
447447 size_t begin = 0 , end = 0 , cnt = 0 ;
448448 uint8_t *ip;
449- if (type_pos + type_str.length () == name.length ()) {
449+ if (type_pos != std::string::npos && type_pos + type_str.length () == name.length ()) {
450450 // IPv4
451451 name.erase (type_pos);
452452 rec->ip_version = IP::v4;
@@ -471,7 +471,7 @@ bool PassiveDNSPlugin::process_ptr_record(std::string name, RecordExtPassiveDNS
471471 } else {
472472 type_str = " .ip6.arpa" ;
473473 type_pos = name.find (type_str);
474- if (type_pos + type_str.length () == name.length ()) {
474+ if (type_pos != std::string::npos && type_pos + type_str.length () == name.length ()) {
475475 // IPv6
476476 name.erase (type_pos);
477477 rec->ip_version = IP::v6;
0 commit comments