Endianness check
Some checks failed
Altlinux build / build-alt (push) Failing after 2m3s
Archlinux build / build-arch (push) Successful in 2m58s
Debian build / build-ubuntu (push) Has been cancelled
Archlinux build / make-test (push) Has been cancelled

This commit is contained in:
Alexey Khromov 2025-05-01 18:10:15 +03:00
parent 144eacc0d6
commit 5eb6ddc45b
4 changed files with 31 additions and 16 deletions

View File

@ -582,7 +582,7 @@ s_nodelist *nodelist_open(const char *dir, char *name, int mode)
return NULL;
}
}
DEB((D_NODELIST, "nodelist_open: endianness = %x", (uint32_t) tmp.endian));
return xmemcpy(&tmp, sizeof(s_nodelist));
}
@ -630,6 +630,7 @@ int nodelist_checkheader(s_nodelist *nlp)
(long)nlstat.st_size, (long)nlsize);
return -1;
}
nlp->endian = buffer_getlong(buffer + 12);
return 0;
}
@ -660,7 +661,7 @@ int nodelist_createheader(s_nodelist *nlp)
buffer_putlong(hdrbuf + 0, nlstat.st_mtime);
buffer_putlong(hdrbuf + 4, nlstat.st_size);
buffer_putlong(hdrbuf + 12, (long) 0xDEADBEEF);
if( fseek(nlp->fp_index, 0L, SEEK_SET) == -1 )
{
logerr("cannot seek to zero offset of index");
@ -754,7 +755,9 @@ int nodelist_findindex(s_nodelist *nlp, s_bni *bni, s_faddr addr)
bni->point = buffer_getint(p + 6);
bni->hub = buffer_getint(p + 8);
bni->offset = buffer_getlong(p + 10);
if ((uint32_t)nlp->endian == 0xBEEFDEAD) {
swap_long((char *)&bni->offset);
}
DEB((D_NODELIST, "nodelist: findindex found" ));
return 0;
}

View File

@ -253,10 +253,10 @@ int checkmasks(const char *masks, const char *str)
*/
char *buffer_putlong(char *buffer, long val)
{
buffer[0] = ( ((unsigned long) val) ) & 0xff;
buffer[1] = ( ((unsigned long) val) >> 8 ) & 0xff;
buffer[2] = ( ((unsigned long) val) >> 16 ) & 0xff;
buffer[3] = ( ((unsigned long) val) >> 24 ) & 0xff;
buffer[0] = ( ((uint_least32_t) val) ) & 0xff;
buffer[1] = ( ((uint_least32_t) val) >> 8 ) & 0xff;
buffer[2] = ( ((uint_least32_t) val) >> 16 ) & 0xff;
buffer[3] = ( ((uint_least32_t) val) >> 24 ) & 0xff;
return buffer;
}
@ -273,8 +273,8 @@ char *buffer_putlong(char *buffer, long val)
*/
char *buffer_putint(char *buffer, int val)
{
buffer[0] = ( ((unsigned int) val) ) & 0xff;
buffer[1] = ( ((unsigned int) val) >> 8 ) & 0xff;
buffer[0] = ( ((uint_least16_t) val) ) & 0xff;
buffer[1] = ( ((uint_least16_t) val) >> 8 ) & 0xff;
return buffer;
}
@ -290,10 +290,10 @@ char *buffer_putint(char *buffer, int val)
*/
long buffer_getlong(const char *buffer)
{
return ( (unsigned long) ((unsigned char) buffer[0]) )
| ( (unsigned long) ((unsigned char) buffer[1]) << 8 )
| ( (unsigned long) ((unsigned char) buffer[2]) << 16 )
| ( (unsigned long) ((unsigned char) buffer[3]) << 24 );
return (long)( (uint_least32_t) ((unsigned char) buffer[0]) )
| ( (uint_least32_t) ((unsigned char) buffer[1]) << 8 )
| ( (uint_least32_t) ((unsigned char) buffer[2]) << 16 )
| ( (uint_least32_t) ((unsigned char) buffer[3]) << 24 );
}
/*****************************************************************************
@ -307,8 +307,17 @@ long buffer_getlong(const char *buffer)
*/
int buffer_getint(const char *buffer)
{
return ( (unsigned int) ((unsigned char) buffer[0]) )
| ( (unsigned int) ((unsigned char) buffer[1]) << 8 );
return (int)( (uint_least16_t) ((unsigned char) buffer[0]) )
| ( (uint_least16_t) ((unsigned char) buffer[1]) << 8 );
}
void swap_long(char *buffer){
char *temp = xmemcpy(buffer, sizeof(uint32_t));
temp[0] = buffer[2];
temp[1] = buffer[3];
temp[2] = buffer[0];
temp[3] = buffer[1];
memcpy(buffer,temp,sizeof(uint32_t));
}
void printf_usage(const char *ident, const char *fmt, ...)

View File

@ -27,7 +27,7 @@
* 0x0000 4 bytes Nodelist file date
* 0x0004 4 bytes Nodelist file size
* 0x0008 4 bytes Total number of entries in index file
* 0x000c 4 bytes Unused
* 0x000c 4 bytes ENDIANNES MARK
*
* Nodelist index is an array of next entries:
*
@ -123,6 +123,7 @@ typedef struct nodelist
char name_index[BF_MAXPATH+1];
char name_nodelist[BF_MAXPATH+1];
long entries;
long endian;
}
s_nodelist;

View File

@ -189,8 +189,10 @@ char *buffer_putlong(char *buffer, long val);
char *buffer_putint(char *buf, int val);
long buffer_getlong(const char *buf);
int buffer_getint(const char *buf);
void swap_long(char *buffer);
void printf_usage(const char *ident, const char *fmt, ...);
/* u_pkt.c */
int pkt_createpacket(const char *pktname, const s_packet *pkt);