tcpdump: fix XXX in fdata()

2021-04-12 Thread Guilherme Janczak
It appears that all the fdata() calls use fmt strings supplied at 
compile time so this patch makes all the same assumptions, the only 
change is that it uses the right functions for the job.


Index: usr.sbin/tcpdump/smbutil.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/smbutil.c,v
retrieving revision 1.10
diff -u -p -u -r1.10 smbutil.c
--- usr.sbin/tcpdump/smbutil.c  25 Oct 2015 18:25:41 -  1.10
+++ usr.sbin/tcpdump/smbutil.c  13 Apr 2021 00:03:54 -
@@ -549,10 +549,9 @@ const uchar *fdata(const uchar *buf, con
 case '[':
   fmt++;
   if (buf>=maxbuf) return(buf);
-  memset(s, 0, sizeof(s));
-  p = strchr(fmt,']');
-  strncpy(s,fmt,p-fmt);/* XXX? */
-  fmt = p+1;
+  p = memccpy(s, fmt, ']', sizeof(s);
+  fmt += p-s;
+  *--p = '\0';
   buf = fdata1(buf,s,maxbuf);
   if (buf == NULL)
return(NULL);



Re: tcpdump: fix XXX in fdata()

2021-04-12 Thread Guilherme Janczak
I apologize, I managed to slip in a syntax error. 
This reply has the missing close parenthesis.


Index: usr.sbin/tcpdump/smbutil.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/smbutil.c,v
retrieving revision 1.10
diff -u -p -u -r1.10 smbutil.c
--- usr.sbin/tcpdump/smbutil.c  25 Oct 2015 18:25:41 -  1.10
+++ usr.sbin/tcpdump/smbutil.c  13 Apr 2021 00:16:35 -
@@ -549,10 +549,9 @@ const uchar *fdata(const uchar *buf, con
 case '[':
   fmt++;
   if (buf>=maxbuf) return(buf);
-  memset(s, 0, sizeof(s));
-  p = strchr(fmt,']');
-  strncpy(s,fmt,p-fmt);/* XXX? */
-  fmt = p+1;
+  p = memccpy(s, fmt, ']', sizeof(s));
+  fmt += p-s;
+  *--p = '\0';
   buf = fdata1(buf,s,maxbuf);
   if (buf == NULL)
return(NULL);



On 21/04/13 12:07AM, Guilherme Janczak wrote:
> It appears that all the fdata() calls use fmt strings supplied at 
> compile time so this patch makes all the same assumptions, the only 
> change is that it uses the right functions for the job.
>
> ...