Skip to content
Snippets Groups Projects
Commit 5cfffef8 authored by Deucе's avatar Deucе :ok_hand_tone4: Committed by Rob Swindell
Browse files

Overhaul LZH code

parent b6b57d12
No related branches found
No related tags found
1 merge request!489Overhaul LZH code
......@@ -20,4 +20,4 @@ endif
# Test build
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 @@
#ifdef __cplusplus
extern "C" {
#endif
LZHEXPORT int32_t lzh_encode(uint8_t *inbuf, int32_t inlen, uint8_t *outbuf);
LZHEXPORT int32_t lzh_decode(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 uint32_t lzh_decode(const uint8_t *inbuf, uint32_t inlen, uint8_t *outbuf, size_t outlen);
#ifdef __cplusplus
}
#endif
......
......@@ -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)
{
uchar* lzhbuf=NULL;
int lzhlen;
uint32_t lzhlen;
int retval;
size_t n;
off_t l;
......@@ -113,7 +113,7 @@ int smb_addmsg(smb_t* smb, smbmsg_t* msg, int storage, int dupechk_hashes
/* LZH compress? */
if(xlat==XLAT_LZH && bodylen+taillen>=SDT_BLOCK_LEN
&& (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
&& smb_datblocks(lzhlen+(sizeof(xlat)*2)+taillen)
< smb_datblocks(bodylen+taillen)) {
......
......@@ -23,6 +23,9 @@
#include <stdlib.h> /* malloc/realloc/free */
#include <string.h> /* strlen */
/* XPDev */
#include "xpendian.h"
/* SMB-specific */
#include "smblib.h"
#include "base64.h"
......@@ -38,7 +41,9 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode)
uint16_t xlat;
uint i;
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) {
safe_snprintf(smb->last_error, sizeof(smb->last_error)
......@@ -146,7 +151,8 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode)
free(preamble);
return(NULL);
}
lzhlen=*(int32_t*)lzhbuf;
memcpy(&lzhlen, lzhbuf, sizeof(lzhlen));
lzhlen = LE_INT32(lzhlen);
if((p=(char*)realloc(buf,l+lzhlen+3L))==NULL) {
safe_snprintf(smb->last_error, sizeof(smb->last_error)
,"%s realloc failure of %d bytes for text buffer"
......@@ -157,7 +163,16 @@ char* smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, uint mode)
return(NULL);
}
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);
l+=lzhlen;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment