Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/isdn/isdntrace using sizeof(char *) to compute the ...
details: https://anonhg.NetBSD.org/src/rev/ac837a3bf6c4
branches: trunk
changeset: 790700:ac837a3bf6c4
user: christos <christos%NetBSD.org@localhost>
date: Sat Oct 19 17:09:38 2013 +0000
description:
using sizeof(char *) to compute the size of a buffer is not going to work
very well.
diffstat:
usr.sbin/isdn/isdntrace/trace.c | 31 +++++++++++++++++--------------
1 files changed, 17 insertions(+), 14 deletions(-)
diffs (99 lines):
diff -r 2a78cd2feee2 -r ac837a3bf6c4 usr.sbin/isdn/isdntrace/trace.c
--- a/usr.sbin/isdn/isdntrace/trace.c Sat Oct 19 17:08:15 2013 +0000
+++ b/usr.sbin/isdn/isdntrace/trace.c Sat Oct 19 17:09:38 2013 +0000
@@ -35,7 +35,7 @@
* trace.c - print traces of D (B) channel activity for isdn4bsd
* -------------------------------------------------------------
*
- * $Id: trace.c,v 1.13 2011/08/31 16:24:59 plunky Exp $
+ * $Id: trace.c,v 1.14 2013/10/19 17:09:38 christos Exp $
*
* $FreeBSD$
*
@@ -80,7 +80,7 @@
__dead static void usage( void );
static void exit_hdl( void );
static void reopenfiles( int );
-void add_datetime(char *filename, char *rfilename);
+void add_datetime(const char *filename, char *rfilename, size_t);
char * fmt_hdr(struct i4b_trace_hdr *hdr, int frm_len);
/*---------------------------------------------------------------------------*
@@ -242,7 +242,7 @@
snprintf(BPfilename, sizeof(BPfilename), "%s%d",
BIN_FILE_NAME, unit);
- add_datetime(BPfilename, rBPfilename);
+ add_datetime(BPfilename, rBPfilename, sizeof(rBPfilename));
if ((BP = fopen(rBPfilename, "w")) == NULL)
{
@@ -321,7 +321,7 @@
else
strlcpy(outfilename, outfile, sizeof(outfilename));
- add_datetime(outfilename, routfilename);
+ add_datetime(outfilename, routfilename, sizeof(routfilename));
if ((Fout = fopen(routfilename, "w")) == NULL)
{
@@ -777,7 +777,7 @@
{
fclose(Fout);
- add_datetime(outfilename, routfilename);
+ add_datetime(outfilename, routfilename, sizeof(routfilename));
if ((Fout = fopen(routfilename, "a")) == NULL)
{
@@ -806,7 +806,7 @@
fclose(BP);
- add_datetime(BPfilename, rBPfilename);
+ add_datetime(BPfilename, rBPfilename, sizeof(rBPfilename));
if ((BP = fopen(rBPfilename, "a")) == NULL)
{
@@ -832,19 +832,21 @@
}
void
-add_datetime(char *filename, char *rfilename)
+add_datetime(const char *filename, char *rfilename, size_t len)
{
time_t timeb;
+ FILE *fx;
+ int c;
struct tm *tmp;
- FILE *fx;
time(&timeb);
tmp = localtime(&timeb);
- snprintf(rfilename, sizeof(rfilename), "%s-", filename);
+ c = snprintf(rfilename, len, "%s-", filename);
+ if (c < 0)
+ return;
- strftime(rfilename+strlen(rfilename), MAXPATHLEN-strlen(rfilename)-1,
- "%Y%m%d-%H%M%S", tmp);
+ strftime(rfilename + c, len - c - 1, "%Y%m%d-%H%M%S", tmp);
if ((fx = fopen(rfilename, "r")) != NULL)
{
@@ -855,10 +857,11 @@
time(&timeb);
tmp = localtime(&timeb);
- snprintf(rfilename, sizeof(rfilename), "%s-", filename);
+ c = snprintf(rfilename, len, "%s-", filename);
+ if (c < 0)
+ return;
- strftime(rfilename+strlen(rfilename), MAXPATHLEN-strlen(rfilename)-1,
- "%Y%m%d-%H%M%S", tmp);
+ strftime(rfilename, len - c - 1, "%Y%m%d-%H%M%S", tmp);
}
}
Home |
Main Index |
Thread Index |
Old Index