Skip to content
Snippets Groups Projects
Commit dcf958cd authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Merge branch 'lzh-refactor' into 'master'

Overhaul LZH code

See merge request !489
parents 868b7d82 5cfffef8
No related branches found
No related tags found
1 merge request!489Overhaul LZH code
Pipeline #7609 passed
...@@ -20,4 +20,4 @@ endif ...@@ -20,4 +20,4 @@ endif
# Test build # Test build
lzh${EXEFILE}: lzh.c lzh${EXEFILE}: lzh.c
$(QUIET)$(CC) -std=c11 $(CFLAGS) -DLZH_TEST $(CCFLAGS) -o $@ $< $(QUIET)$(CC) -std=c11 $(CFLAGS) -Wall -pedantic -DLZH_TEST $(CCFLAGS) -o $@ $<
This diff is collapsed.
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
LZHEXPORT int32_t lzh_encode(uint8_t *inbuf, int32_t inlen, uint8_t *outbuf); LZHEXPORT uint32_t lzh_encode(const uint8_t *inbuf, uint32_t inlen, uint8_t *outbuf, size_t outlen);
LZHEXPORT int32_t lzh_decode(uint8_t *inbuf, int32_t inlen, uint8_t *outbuf); LZHEXPORT uint32_t lzh_decode(const uint8_t *inbuf, uint32_t inlen, uint8_t *outbuf, size_t outlen);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -34,7 +34,7 @@ int smb_addmsg(smb_t* smb, smbmsg_t* msg, int storage, int dupechk_hashes ...@@ -34,7 +34,7 @@ int smb_addmsg(smb_t* smb, smbmsg_t* msg, int storage, int dupechk_hashes
,uint16_t xlat, const uchar* body, const uchar* tail) ,uint16_t xlat, const uchar* body, const uchar* tail)
{ {
uchar* lzhbuf=NULL; uchar* lzhbuf=NULL;
int lzhlen; uint32_t lzhlen;
int retval; int retval;
size_t n; size_t n;
off_t l; off_t l;
...@@ -113,7 +113,7 @@ int smb_addmsg(smb_t* smb, smbmsg_t* msg, int storage, int dupechk_hashes ...@@ -113,7 +113,7 @@ int smb_addmsg(smb_t* smb, smbmsg_t* msg, int storage, int dupechk_hashes
/* LZH compress? */ /* LZH compress? */
if(xlat==XLAT_LZH && bodylen+taillen>=SDT_BLOCK_LEN if(xlat==XLAT_LZH && bodylen+taillen>=SDT_BLOCK_LEN
&& (lzhbuf=(uchar *)malloc(bodylen*2))!=NULL) { && (lzhbuf=(uchar *)malloc(bodylen*2))!=NULL) {
lzhlen=lzh_encode((uchar*)body,bodylen-sizeof(xlat),lzhbuf); lzhlen=lzh_encode((uchar*)body,bodylen-sizeof(xlat),lzhbuf,bodylen*2);
if(lzhlen>1 if(lzhlen>1
&& smb_datblocks(lzhlen+(sizeof(xlat)*2)+taillen) && smb_datblocks(lzhlen+(sizeof(xlat)*2)+taillen)
< smb_datblocks(bodylen+taillen)) { < smb_datblocks(bodylen+taillen)) {
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
#include <stdlib.h> /* malloc/realloc/free */ #include <stdlib.h> /* malloc/realloc/free */
#include <string.h> /* strlen */ #include <string.h> /* strlen */
/* XPDev */
#include "xpendian.h"
/* SMB-specific */ /* SMB-specific */
#include "smblib.h" #include "smblib.h"
#include "base64.h" #include "base64.h"
...@@ -38,7 +41,9 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode) ...@@ -38,7 +41,9 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode)
uint16_t xlat; uint16_t xlat;
uint i; uint i;
int lzh; /* bool */ int lzh; /* bool */
int l=0,lzhlen,length; uint32_t lzhlen;
uint32_t lzh_decoded;
int l=0,length;
if((buf=(char*)malloc(sizeof(char)))==NULL) { if((buf=(char*)malloc(sizeof(char)))==NULL) {
safe_snprintf(smb->last_error, sizeof(smb->last_error) safe_snprintf(smb->last_error, sizeof(smb->last_error)
...@@ -146,7 +151,8 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode) ...@@ -146,7 +151,8 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode)
free(preamble); free(preamble);
return(NULL); return(NULL);
} }
lzhlen=*(int32_t*)lzhbuf; memcpy(&lzhlen, lzhbuf, sizeof(lzhlen));
lzhlen = LE_INT32(lzhlen);
if((p=(char*)realloc(buf,l+lzhlen+3L))==NULL) { if((p=(char*)realloc(buf,l+lzhlen+3L))==NULL) {
safe_snprintf(smb->last_error, sizeof(smb->last_error) safe_snprintf(smb->last_error, sizeof(smb->last_error)
,"%s realloc failure of %d bytes for text buffer" ,"%s realloc failure of %d bytes for text buffer"
...@@ -157,7 +163,16 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode) ...@@ -157,7 +163,16 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode)
return(NULL); return(NULL);
} }
buf=p; buf=p;
lzh_decode((uint8_t *)lzhbuf,length,(uint8_t *)buf+l); lzh_decoded = lzh_decode((uint8_t *)lzhbuf,length,(uint8_t *)buf+l,l+lzhlen+3);
if (lzh_decoded < lzhlen) {
safe_snprintf(smb->last_error, sizeof(smb->last_error)
,"%s lzh_decode failure got %" PRIu32 " of %" PRIu32 " bytes for text buffer"
, __FUNCTION__, lzh_decoded, lzhlen);
free(lzhbuf);
free(buf);
free(preamble);
return(NULL);
}
free(lzhbuf); free(lzhbuf);
l+=lzhlen; l+=lzhlen;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment