aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors
diff options
context:
space:
mode:
authorsahlberg <sahlberg@f5534014-38df-0310-8fa8-9805f1628bb7>2005-09-21 20:05:13 +0000
committersahlberg <sahlberg@f5534014-38df-0310-8fa8-9805f1628bb7>2005-09-21 20:05:13 +0000
commit1d3d2f48dfac050ae9f5206a9277382e714b319e (patch)
treea783dc714a4fd4a95910eeb9c3dbe924a1723c14 /epan/dissectors
parent82d60c6031299bd16c344f50cd4cafb9490e2430 (diff)
get rid of strcpy in packet-ntp.c
at the same time change ntp_fmt_ts to return a pointer to ian ep-allocated buffer. remove the redundant buffer parameter in the signature and change all callers. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@15939 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/dissectors')
-rw-r--r--epan/dissectors/packet-3g-a11.c13
-rw-r--r--epan/dissectors/packet-mip.c5
-rw-r--r--epan/dissectors/packet-mpls-echo.c5
-rw-r--r--epan/dissectors/packet-ntp.c85
-rw-r--r--epan/dissectors/packet-ntp.h2
-rw-r--r--epan/dissectors/packet-rtcp.c6
6 files changed, 61 insertions, 55 deletions
diff --git a/epan/dissectors/packet-3g-a11.c b/epan/dissectors/packet-3g-a11.c
index 6f656e16dc..7e5cc9540c 100644
--- a/epan/dissectors/packet-3g-a11.c
+++ b/epan/dissectors/packet-3g-a11.c
@@ -766,7 +766,6 @@ dissect_a11( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
guint8 flags;
size_t offset=0;
const guint8 *reftime;
- gchar buff[NTP_TS_SIZE];
if (!tvb_bytes_exist(tvb, offset, 1))
return 0; /* not enough data to check message type */
@@ -832,7 +831,7 @@ dissect_a11( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(a11_tree, hf_a11_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
@@ -872,7 +871,7 @@ dissect_a11( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(a11_tree, hf_a11_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
@@ -906,7 +905,7 @@ dissect_a11( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(a11_tree, hf_a11_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
@@ -945,7 +944,7 @@ dissect_a11( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(a11_tree, hf_a11_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
@@ -979,7 +978,7 @@ dissect_a11( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(a11_tree, hf_a11_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
@@ -1018,7 +1017,7 @@ dissect_a11( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(a11_tree, hf_a11_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
diff --git a/epan/dissectors/packet-mip.c b/epan/dissectors/packet-mip.c
index 9444c471b2..ff6f1dd424 100644
--- a/epan/dissectors/packet-mip.c
+++ b/epan/dissectors/packet-mip.c
@@ -262,7 +262,6 @@ dissect_mip( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
guint8 flags;
size_t offset=0;
const guint8 *reftime;
- gchar buff[NTP_TS_SIZE];
/* Make entries in Protocol column and Info column on summary display */
@@ -322,7 +321,7 @@ dissect_mip( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(mip_tree, hf_mip_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
@@ -362,7 +361,7 @@ dissect_mip( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_bytes_format(mip_tree, hf_mip_ident, tvb, offset, 8,
reftime,
"Identification: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
offset += 8;
} /* if tree */
diff --git a/epan/dissectors/packet-mpls-echo.c b/epan/dissectors/packet-mpls-echo.c
index 9f0df19381..575c7506e7 100644
--- a/epan/dissectors/packet-mpls-echo.c
+++ b/epan/dissectors/packet-mpls-echo.c
@@ -943,7 +943,6 @@ dissect_mpls_echo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree *mpls_echo_tree = NULL, *mpls_echo_gflags = NULL;
guint8 msgtype;
const guint8 *ts_sent, *ts_rec;
- gchar buff[NTP_TS_SIZE];
/* If version != 1 we assume it's not an mpls ping packet */
if (!tvb_bytes_exist(tvb, 0, 5)) {
@@ -1020,10 +1019,10 @@ dissect_mpls_echo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
/* Using NTP routine to calculate the timestamp */
ts_sent = tvb_get_ptr(tvb, 16, 8);
proto_tree_add_bytes_format(mpls_echo_tree, hf_mpls_echo_ts_sent, tvb,
- offset + 16, 8, ts_sent, "Timestamp Sent: %s", ntp_fmt_ts(ts_sent, buff));
+ offset + 16, 8, ts_sent, "Timestamp Sent: %s", ntp_fmt_ts(ts_sent));
ts_rec = tvb_get_ptr(tvb, 24, 8);
proto_tree_add_bytes_format(mpls_echo_tree, hf_mpls_echo_ts_rec, tvb,
- offset + 24, 8, ts_rec, "Timestamp Received: %s", ntp_fmt_ts(ts_rec, buff));
+ offset + 24, 8, ts_rec, "Timestamp Received: %s", ntp_fmt_ts(ts_rec));
}
}
diff --git a/epan/dissectors/packet-ntp.c b/epan/dissectors/packet-ntp.c
index 9430099d33..320af8b5d1 100644
--- a/epan/dissectors/packet-ntp.c
+++ b/epan/dissectors/packet-ntp.c
@@ -38,6 +38,7 @@
#include <epan/packet.h>
#include <epan/addr_resolv.h>
+#include <epan/emem.h>
#include "packet-ntp.h"
/*
@@ -367,38 +368,40 @@ static const char *mon_names[12] = {
/* ntp_fmt_ts - converts NTP timestamp to human readable string.
* reftime - 64bit timestamp (IN)
- * buff - string buffer for result (OUT)
- * returns pointer to filled buffer.
+ * returns pointer to filled buffer. This buffer will be freed automatically once
+ * dissection of the next packet occurs.
*/
char *
-ntp_fmt_ts(const guint8 *reftime, char* buff)
+ntp_fmt_ts(const guint8 *reftime)
{
guint32 tempstmp, tempfrac;
time_t temptime;
struct tm *bd;
double fractime;
+ char *buff;
tempstmp = pntohl(&reftime[0]);
tempfrac = pntohl(&reftime[4]);
if ((tempstmp == 0) && (tempfrac == 0)) {
- strcpy (buff, "NULL");
- return buff;
- } else {
- temptime = tempstmp - (guint32) NTP_BASETIME;
- bd = gmtime(&temptime);
- if (bd != NULL) {
- fractime = bd->tm_sec + tempfrac / 4294967296.0;
- g_snprintf(buff, NTP_TS_SIZE,
- "%s %2d, %d %02d:%02d:%07.4f UTC",
- mon_names[bd->tm_mon],
- bd->tm_mday,
- bd->tm_year + 1900,
- bd->tm_hour,
- bd->tm_min,
- fractime);
- } else
- strncpy(buff, "Not representable", NTP_TS_SIZE);
+ return "NULL";
+ }
+
+ temptime = tempstmp - (guint32) NTP_BASETIME;
+ bd = gmtime(&temptime);
+ if(!bd){
+ return "Not representable";
}
+
+ fractime = bd->tm_sec + tempfrac / 4294967296.0;
+ buff=ep_alloc(NTP_TS_SIZE);
+ g_snprintf(buff, NTP_TS_SIZE,
+ "%s %2d, %d %02d:%02d:%07.4f UTC",
+ mon_names[bd->tm_mon],
+ bd->tm_mday,
+ bd->tm_year + 1900,
+ bd->tm_hour,
+ bd->tm_min,
+ fractime);
return buff;
}
@@ -466,7 +469,7 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
const guint8 *org;
const guint8 *rec;
const guint8 *xmt;
- gchar buff[NTP_TS_SIZE];
+ gchar *buff;
int i;
int macofs;
gint maclen;
@@ -483,13 +486,13 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
*/
stratum = tvb_get_guint8(tvb, 1);
if (stratum == 0) {
- strcpy (buff, "Peer Clock Stratum: unspecified or unavailable (%u)");
+ buff="Peer Clock Stratum: unspecified or unavailable (%u)";
} else if (stratum == 1) {
- strcpy (buff, "Peer Clock Stratum: primary reference (%u)");
+ buff="Peer Clock Stratum: primary reference (%u)";
} else if ((stratum >= 2) && (stratum <= 15)) {
- strcpy (buff, "Peer Clock Stratum: secondary reference (%u)");
+ buff="Peer Clock Stratum: secondary reference (%u)";
} else {
- strcpy (buff, "Peer Clock Stratum: reserved: %u");
+ buff="Peer Clock Stratum: reserved: %u";
}
proto_tree_add_uint_format(ntp_tree, hf_ntp_stratum, tvb, 1, 1,
stratum, buff, stratum);
@@ -546,23 +549,29 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
*/
refid = tvb_get_ptr(tvb, 12, 4);
if (stratum <= 1) {
- g_snprintf (buff, sizeof buff,
- "Unindentified reference source '%.4s'",
- refid);
+ int buffpos=0;
+ buff=ep_alloc(NTP_TS_SIZE);
+ buffpos += g_snprintf (buff, NTP_TS_SIZE,
+ "Unindentified reference source '%.4s'",
+ refid);
for (i = 0; primary_sources[i].id; i++) {
if (memcmp (refid, primary_sources[i].id,
4) == 0) {
- strcpy (buff, primary_sources[i].data);
+ buffpos += g_snprintf(buff, NTP_TS_SIZE-buffpos, "%s", primary_sources[i].data);
break;
}
}
} else {
- buff[sizeof(buff) - 1] = '\0';
+ int buffpos=0;
+ buff=ep_alloc(NTP_TS_SIZE);
refid_addr = tvb_get_ipv4(tvb, 12);
- strncpy (buff, get_hostname (refid_addr),
- sizeof(buff));
- if (buff[sizeof(buff) - 1] != '\0')
- strcpy(&buff[sizeof(buff) - 4], "...");
+ buffpos += g_snprintf(buff, NTP_TS_SIZE, get_hostname (refid_addr));
+ if (buffpos>=(NTP_TS_SIZE-1)){
+ buff[NTP_TS_SIZE-4]='.';
+ buff[NTP_TS_SIZE-3]='.';
+ buff[NTP_TS_SIZE-2]='.';
+ buff[NTP_TS_SIZE-1]=0;
+ }
}
proto_tree_add_bytes_format(ntp_tree, hf_ntp_refid, tvb, 12, 4,
refid,
@@ -575,7 +584,7 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
proto_tree_add_bytes_format(ntp_tree, hf_ntp_reftime, tvb, 16, 8,
reftime,
"Reference Clock Update Time: %s",
- ntp_fmt_ts(reftime, buff));
+ ntp_fmt_ts(reftime));
/* Originate Timestamp: This is the time at which the request departed
* the client for the server.
@@ -584,7 +593,7 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
proto_tree_add_bytes_format(ntp_tree, hf_ntp_org, tvb, 24, 8,
org,
"Originate Time Stamp: %s",
- ntp_fmt_ts(org, buff));
+ ntp_fmt_ts(org));
/* Receive Timestamp: This is the time at which the request arrived at
* the server.
@@ -593,7 +602,7 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
proto_tree_add_bytes_format(ntp_tree, hf_ntp_rec, tvb, 32, 8,
rec,
"Receive Time Stamp: %s",
- ntp_fmt_ts(rec, buff));
+ ntp_fmt_ts(rec));
/* Transmit Timestamp: This is the time at which the reply departed the
* server for the client.
@@ -602,7 +611,7 @@ dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
proto_tree_add_bytes_format(ntp_tree, hf_ntp_xmt, tvb, 40, 8,
xmt,
"Transmit Time Stamp: %s",
- ntp_fmt_ts(xmt, buff));
+ ntp_fmt_ts(xmt));
/* MAX_MAC_LEN is the largest message authentication code
* (MAC) length. If we have more data left in the packet
diff --git a/epan/dissectors/packet-ntp.h b/epan/dissectors/packet-ntp.h
index 889231aa21..21c3730bbb 100644
--- a/epan/dissectors/packet-ntp.h
+++ b/epan/dissectors/packet-ntp.h
@@ -33,6 +33,6 @@
#define NTP_BASETIME 2208988800ul
#define NTP_TS_SIZE 100
-extern char * ntp_fmt_ts(const guint8 *reftime, char* buff);
+extern char * ntp_fmt_ts(const guint8 *reftime);
#endif
diff --git a/epan/dissectors/packet-rtcp.c b/epan/dissectors/packet-rtcp.c
index 86df65bfd5..bb534f0de2 100644
--- a/epan/dissectors/packet-rtcp.c
+++ b/epan/dissectors/packet-rtcp.c
@@ -1370,12 +1370,12 @@ dissect_rtcp_sr( packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tree *tree
unsigned int count )
{
#if 0
- gchar buff[ NTP_TS_SIZE ];
+ gchar *buff;
char* ptime = tvb_get_ptr( tvb, offset, 8 );
/* Retreive the NTP timestamp. Using the NTP dissector for this */
- ntp_fmt_ts( ptime, buff );
- proto_tree_add_string_format( tree, hf_rtcp_ntp, tvb, offset, 8, ( const char* ) &buff, "NTP timestamp: %s", &buff );
+ buff=ntp_fmt_ts(ptime);
+ proto_tree_add_string_format( tree, hf_rtcp_ntp, tvb, offset, 8, ( const char* ) buff, "NTP timestamp: %s", buff );
free( ptime ); ??????????????????????????????????????????????????????????????????
offset += 8;
#else