Skip to content

Commit

Permalink
Fix DNSCache_GetCNameFromCache
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenjoiner committed Sep 19, 2024
1 parent fda179a commit afd0e5f
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions dnscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,22 +663,23 @@ static int DNSCache_GetRawRecordsFromCache(__in const char *Name,

Cht_Node *Node = NULL; /* Important */

if( snprintf(Name_Type_Class,
sizeof(Name_Type_Class),
"%s\1%X\1%X",
Name,
Type,
Klass
)
>= sizeof(Name_Type_Class)
) {
int KeyLength = snprintf(Name_Type_Class,
sizeof(Name_Type_Class),
"%s\1%X\1%X",
Name,
Type,
Klass
);

if( KeyLength >= sizeof(Name_Type_Class) )
{
return -609;
}

do
{
Node = DNSCache_FindFromCache(Name_Type_Class,
strlen(Name_Type_Class) + 1,
KeyLength + 1,
Node,
CurrentTime
);
Expand All @@ -703,11 +704,7 @@ static int DNSCache_GetRawRecordsFromCache(__in const char *Name,
}

/* Skip key to get data */
for(CacheItr = MapStart + Node->Offset + 1;
*CacheItr != '\0';
++CacheItr
);
++CacheItr;
CacheItr = MapStart + Node->Offset + 1 + KeyLength + 1;

/* Now the data position */
switch( Type )
Expand All @@ -721,7 +718,7 @@ static int DNSCache_GetRawRecordsFromCache(__in const char *Name,

default:
if( g->RawData(g, Name, Type, Klass, CacheItr,
MapStart + Node->Offset + Node->UsedLength - CacheItr,
Node->UsedLength - 1 - KeyLength - 1,
NewTTL) != 0 )
{
return -256;
Expand All @@ -741,21 +738,23 @@ static Cht_Node *DNSCache_GetCNameFromCache(__in char *Name,
{
char Name_Type_Class[253 + 1 + 4 + 1 + 4 + 1];
Cht_Node *Node = NULL;
int KeyLength = snprintf(Name_Type_Class,
sizeof(Name_Type_Class),
"%s\1%X\1%X",
Name,
DNS_TYPE_CNAME,
1
);

if( snprintf(Name_Type_Class,
sizeof(Name_Type_Class),
"%s\1%X\1%X", Name,
DNS_TYPE_CNAME,
1) >= sizeof(Name_Type_Class)
)
if( KeyLength >= sizeof(Name_Type_Class) )
{
return NULL;
}

do
{
Node = DNSCache_FindFromCache(Name_Type_Class,
strlen(Name_Type_Class) + 1,
KeyLength + 1,
Node,
CurrentTime
);
Expand All @@ -764,7 +763,13 @@ static Cht_Node *DNSCache_GetCNameFromCache(__in char *Name,
return NULL;
}

strcpy(Buffer, MapStart + Node->Offset + 1 + strlen(Name_Type_Class) + 1);
/* No extra ending char */
strncpy(Buffer,
MapStart + Node->Offset + 1 + KeyLength + 1,
Node->UsedLength - 1 - KeyLength - 1
);
Buffer[Node->UsedLength - 1 - KeyLength - 1] = '\x0';

return Node;

} while( TRUE );
Expand Down

0 comments on commit afd0e5f

Please sign in to comment.