mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-11 15:32:51 +00:00
Fixed nasty bug in createHlr() that was corrupting HLR file.
This commit is contained in:
parent
613d542061
commit
28c8fcfbc9
16
hlrdata.c
16
hlrdata.c
@ -19,6 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
#include "mphlr.h"
|
#include "mphlr.h"
|
||||||
|
|
||||||
|
int hlrGetRecordLength(unsigned char *hlr,int hofs);
|
||||||
|
|
||||||
int bcompare(unsigned char *a,unsigned char *b,size_t len)
|
int bcompare(unsigned char *a,unsigned char *b,size_t len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -183,8 +185,14 @@ int createHlr(char *did,char *sid) {
|
|||||||
sid[0]=hexdigit[1+(random()&0xe)];
|
sid[0]=hexdigit[1+(random()&0xe)];
|
||||||
if (debug>1) fprintf(stderr,"Creating new HLR entry with sid %s\n",sid);
|
if (debug>1) fprintf(stderr,"Creating new HLR entry with sid %s\n",sid);
|
||||||
|
|
||||||
/* Find first free byte of HLR */
|
/* Find first free byte of HLR.
|
||||||
findHlr(hlr,&record_offset,NULL,NULL);
|
Keep calling findHlr() until we find the end. */
|
||||||
|
while((i=hlrGetRecordLength(hlr,record_offset))>0)
|
||||||
|
{
|
||||||
|
record_offset+=i;
|
||||||
|
if (debug>1) fprintf(stderr,"Skipping %d bytes to 0x%x\n",i,record_offset);
|
||||||
|
}
|
||||||
|
if (i<0) return setReason("Corrupt HLR: Negative length field encountered.");
|
||||||
|
|
||||||
if (record_offset>=hlr_size)
|
if (record_offset>=hlr_size)
|
||||||
{
|
{
|
||||||
@ -197,6 +205,8 @@ int createHlr(char *did,char *sid) {
|
|||||||
int bytes=hlr_size-record_offset;
|
int bytes=hlr_size-record_offset;
|
||||||
if (bytes<1024) return setReason("<1KB space in HLR");
|
if (bytes<1024) return setReason("<1KB space in HLR");
|
||||||
|
|
||||||
|
if (debug>2) fprintf(stderr,"Creating new HLR entry @ 0x%x\n",record_offset);
|
||||||
|
|
||||||
/* Write shiny fresh new record.
|
/* Write shiny fresh new record.
|
||||||
32bit - record length
|
32bit - record length
|
||||||
32 bytes - SID
|
32 bytes - SID
|
||||||
@ -243,7 +253,7 @@ int hlrGetRecordLength(unsigned char *hlr,int hofs)
|
|||||||
|
|
||||||
if (record_length<0) {
|
if (record_length<0) {
|
||||||
// fix corrupt entries
|
// fix corrupt entries
|
||||||
if (debug>2) fprintf(stderr,"HLR record @ 0x%x ZEROED.\n",hofs,record_length);
|
if (debug>2) fprintf(stderr,"HLR record @ 0x%x ZEROED.\n",hofs);
|
||||||
hlr[hofs+3]=0;
|
hlr[hofs+3]=0;
|
||||||
hlr[hofs+2]=0;
|
hlr[hofs+2]=0;
|
||||||
hlr[hofs+1]=0;
|
hlr[hofs+1]=0;
|
||||||
|
Loading…
Reference in New Issue
Block a user