MCPcopy Create free account
hub / github.com/defold/defold / ReadName

Function ReadName

engine/dlib/src/dlib/mdns.cpp:519–602  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517 }
518
519 static bool ReadName(const uint8_t* data, uint32_t size, uint32_t* offset, char* out, uint32_t out_size)
520 {
521 // RFC 1035 section 4.1.4 name parser with support for compression
522 // pointers. The jump limit keeps malformed packets from looping
523 // forever when they contain cyclic pointers.
524 uint32_t pos = *offset;
525 uint32_t out_len = 0;
526 bool jumped = false;
527 uint32_t jump_count = 0;
528
529 while (true)
530 {
531 if (pos >= size)
532 return false;
533
534 uint8_t len = data[pos];
535
536 if ((len & 0xC0) == 0xC0)
537 {
538 if (pos + 1 >= size)
539 return false;
540
541 uint16_t pointer = (uint16_t) (((len & 0x3F) << 8) | data[pos + 1]);
542 if (pointer >= size)
543 return false;
544
545 if (!jumped)
546 {
547 *offset = pos + 2;
548 jumped = true;
549 }
550
551 pos = pointer;
552 ++jump_count;
553 if (jump_count > 16)
554 return false;
555 continue;
556 }
557
558 ++pos;
559
560 if (len == 0)
561 {
562 if (!jumped)
563 *offset = pos;
564
565 if (out_len == 0)
566 {
567 if (out_size < 1)
568 return false;
569 out[0] = 0;
570 }
571 else
572 {
573 out[out_len - 1] = 0;
574 }
575 return true;
576 }

Callers 7

CollectProbeClaimsFunction · 0.70
SuppressKnownAnswersFunction · 0.70
HandleIncomingQueriesFunction · 0.70
HandleBrowserRecordFunction · 0.70
HandleBrowserResponsesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected