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

smb_msghdr_str_list() print strings with trailing whitespace in quotes

Make it obvious when a message header value string has trailing white-space.
Make this function (and binstr()) thread-safe by eliminating the local static
variable.
parent b7b9a031
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -23,9 +23,8 @@ ...@@ -23,9 +23,8 @@
#include <string.h> /* strcat */ #include <string.h> /* strcat */
#include "smblib.h" #include "smblib.h"
static char *binstr(uchar *buf, uint16_t length) static char *binstr(uchar *buf, uint16_t length, char* str)
{ {
static char str[512];
int i; int i;
str[0]=0; str[0]=0;
...@@ -33,8 +32,13 @@ static char *binstr(uchar *buf, uint16_t length) ...@@ -33,8 +32,13 @@ static char *binstr(uchar *buf, uint16_t length)
if(buf[i] && (buf[i]<' ' || buf[i]>=0x7f) if(buf[i] && (buf[i]<' ' || buf[i]>=0x7f)
&& buf[i]!='\r' && buf[i]!='\n' && buf[i]!='\t') && buf[i]!='\r' && buf[i]!='\n' && buf[i]!='\t')
break; break;
if(i==length) /* not binary */ if(i==length) { /* not binary */
if(length > 0 && buf[length - 1] == ' ') {
sprintf(str, "'%s'", buf);
return str;
}
return((char*)buf); return((char*)buf);
}
for(i=0;i<length;i++) { for(i=0;i<length;i++) {
sprintf(str+strlen(str),"%02X ",buf[i]); sprintf(str+strlen(str),"%02X ",buf[i]);
if(i>=100) { if(i>=100) {
...@@ -48,7 +52,7 @@ static char *binstr(uchar *buf, uint16_t length) ...@@ -48,7 +52,7 @@ static char *binstr(uchar *buf, uint16_t length)
str_list_t smb_msghdr_str_list(smbmsg_t* msg) str_list_t smb_msghdr_str_list(smbmsg_t* msg)
{ {
char tmp[128]; char tmp[512];
int i; int i;
time_t tt; time_t tt;
str_list_t list = strListInit(); str_list_t list = strListInit();
...@@ -102,7 +106,7 @@ str_list_t smb_msghdr_str_list(smbmsg_t* msg) ...@@ -102,7 +106,7 @@ str_list_t smb_msghdr_str_list(smbmsg_t* msg)
default: default:
strListAppendFormat(&list, HFIELD_NAME_FMT "%s" strListAppendFormat(&list, HFIELD_NAME_FMT "%s"
,smb_hfieldtype(msg->hfield[i].type) ,smb_hfieldtype(msg->hfield[i].type)
,binstr((uchar *)msg->hfield_dat[i],msg->hfield[i].length)); ,binstr((uchar *)msg->hfield_dat[i],msg->hfield[i].length,tmp));
break; break;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment