int split_packet_count = 0;
int written_count = 0;
char *filename;
+ size_t filenamelen;
gboolean check_ts;
#ifdef HAVE_PLUGINS
char* init_progfile_dir_error;
out_frame_type = wtap_file_encap(wth);
if (split_packet_count > 0) {
- filename = (char *) g_malloc(strlen(argv[optind+1]) + 20);
+ filenamelen = strlen(argv[optind+1]) + 20;
+ filename = (char *) g_malloc(filenamelen);
if (!filename) {
exit(5);
}
- sprintf(filename, "%s-%05d", argv[optind+1], 0);
+ snprintf(filename, filenamelen, "%s-%05d", argv[optind+1], 0);
} else {
filename = argv[optind+1];
}
exit(1);
}
- sprintf(filename, "%s-%05d",argv[optind+1], count / split_packet_count);
+ snprintf(filename, filenamelen, "%s-%05d",argv[optind+1], count / split_packet_count);
if (verbose) {
fprintf(stderr, "Continuing writing in file %s\n", filename);
val_to_str(code16,table_cops_dqos_transaction_id, "Unknown (0x%04x)"),code16);
/* Write the right data into the 'info field' on the Gui */
- g_snprintf(info,sizeof(info),"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
- strncat(info,val_to_str(code16,table_cops_dqos_transaction_id, "Unknown"), sizeof(info)-strlen(info));
- info[sizeof(info)-1] = '\0';
+ g_snprintf(info,sizeof(info),"COPS %-20s - %s",val_to_str(op_code,cops_op_code_vals, "Unknown"),
+ val_to_str(code16,table_cops_dqos_transaction_id, "Unknown"));
if (check_col(pinfo->cinfo, COL_INFO)) {
col_clear(pinfo->cinfo, COL_INFO);
val_to_str(code16,table_cops_mm_transaction_id, "Unknown (0x%04x)"),code16);
/* Write the right data into the 'info field' on the Gui */
- g_snprintf(info,sizeof(info),"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
- strncat(info,val_to_str(code16,table_cops_mm_transaction_id, "Unknown"), sizeof(info)-strlen(info));
+ g_snprintf(info,sizeof(info),"COPS %-20s - %s",val_to_str(op_code,cops_op_code_vals, "Unknown"),
+ val_to_str(code16,table_cops_mm_transaction_id, "Unknown"));
if (check_col(pinfo->cinfo, COL_INFO)) {
col_clear(pinfo->cinfo, COL_INFO);
return g_strdup_printf("getcwd failed: %s\n",
strerror(errno));
}
- path = g_malloc(strlen(curdir) + 1 + strlen(arg0) + 1);
- strcpy(path, curdir);
- strcat(path, "/");
- strcat(path, arg0);
+ path = g_strdup_printf("%s/%s", curdir, arg0);
g_free(curdir);
prog_pathname = path;
} else {
+ strlen(arg0) + 1);
memcpy(path, path_start, path_component_len);
path[path_component_len] = '\0';
- strcat(path, "/");
- strcat(path, arg0);
+ strncat(path, "/", 2);
+ strncat(path, arg0, strlen(arg0) + 1);
if (access(path, X_OK) == 0) {
/*
* Found it!
/* the "My Captures" sub-directory is created (if it doesn't exist)
by u3util.exe when the U3 Wireshark is first run */
- szPath = g_malloc(strlen(u3devicedocumentpath) + strlen(U3_MY_CAPTURES) + 1);
- strcpy(szPath, u3devicedocumentpath);
- strcat(szPath, U3_MY_CAPTURES);
+ szPath = g_strdup_printf("%s%s", 3devicedocumentpath, U3_MY_CAPTURES);
persdatafile_dir = szPath;
return szPath;
* This is cached, so we don't need to worry about
* allocating multiple ones of them.
*/
- homestring =
- g_malloc(strlen(homedrive) + strlen(homepath) + 1);
- strcpy(homestring, homedrive);
- strcat(homestring, homepath);
+ homestring = g_strdup_printf("%s%s", homedrive, homepath);
/*
* Trim off any trailing slash or backslash.
pref_str[cur_len] = '\n'; cur_len++;
pref_str[cur_len] = '\t'; cur_len++;
}
- sprintf(&pref_str[cur_len], "\"%s\", ", quoted_str);
+ g_snprintf(&pref_str[cur_len], MAX_FMT_PREF_LEN - cur_len, "\"%s\", ", quoted_str);
cur_pos += fmt_len;
cur_len += fmt_len;
}
if (multiple_sources) {
name = src->name;
print_line(stream, 0, "");
- line = g_malloc(strlen(name) + 2); /* <name>:\0 */
- strcpy(line, name);
- strcat(line, ":");
+ line = g_strdup_printf("%s:", name);
print_line(stream, 0, line);
g_free(line);
}
static char errbuf[5+1+11+1]; /* "Error %d" */
if (errnum < 0 || errnum >= sys_nerr) {
- sprintf(errbuf, "Error %d", errnum);
+ g_snprintf(errbuf, 18, "Error %d", errnum);
return errbuf;
} else
return sys_errlist[errnum];
ss=g_malloc(sizeof(afpstat_t));
if(filter){
- ss->filter=g_malloc(strlen(filter)+1);
- strcpy(ss->filter, filter);
+ ss->filter=g_strdup(filter);
} else {
ss->filter=NULL;
}
sp = g_malloc( sizeof(dhcpstat_t) );
sp->hash = g_hash_table_new( g_str_hash, g_str_equal);
if(filter){
- sp->filter=g_malloc(strlen(filter)+1);
- strcpy(sp->filter,filter);
+ sp->filter=g_strdup(filter);
} else {
sp->filter=NULL;
}
p_camelcounter = g_malloc(sizeof(struct camelcounter_t));
if(filter){
- p_camelcounter->filter=g_malloc(strlen(filter)+1);
- strcpy(p_camelcounter->filter,filter);
+ p_camelcounter->filter=g_strdup(filter);
} else {
p_camelcounter->filter=NULL;
}
p_camelsrt = g_malloc(sizeof(struct camelsrt_t));
if(filter){
- p_camelsrt->filter=g_malloc(strlen(filter)+1);
- strcpy(p_camelsrt->filter,filter);
+ p_camelsrt->filter=g_strdup(filter);
} else {
p_camelsrt->filter=NULL;
}
rs->ver=ver;
if(filter){
- rs->filter=g_malloc(strlen(filter)+1);
- strcpy(rs->filter, filter);
+ rs->filter=g_strdup(filter);
} else {
rs->filter=NULL;
}
}
hs = g_malloc(sizeof(h225counter_t));
- hs->filter=g_malloc(strlen(filter)+1);
- strcpy(hs->filter, filter);
+ hs->filter=g_strdup(filter);
h225counter_reset(hs);
}
hs = g_malloc(sizeof(h225rassrt_t));
- hs->filter=g_malloc(strlen(filter)+1);
- strcpy(hs->filter, filter);
+ hs->filter=g_strdup(filter);
h225rassrt_reset(hs);
sp = g_malloc( sizeof(httpstat_t) );
if(filter){
- sp->filter=g_malloc(strlen(filter)+1);
- strcpy(sp->filter,filter);
+ sp->filter=g_strdup(filter);
} else {
sp->filter=NULL;
}
if(pos==str){
register_io_tap(io, i, NULL);
} else if(pos==NULL) {
- tmp=g_malloc(strlen(str)+1);
- strcpy(tmp,str);
+ tmp=g_strdup(str);
register_io_tap(io, i, tmp);
} else {
tmp=g_malloc((pos-str)+1);
}
ms=g_malloc(sizeof(mgcpstat_t));
- ms->filter=g_malloc(strlen(filter)+1);
- strcpy(ms->filter, filter);
+ ms->filter=g_strdup(filter);
for(i=0;i<NUM_TIMESTATS;i++) {
ms->rtd[i].num=0;
rs=new_phs_t(NULL);
if(filter){
- rs->filter=g_malloc(strlen(filter)+1);
- strcpy(rs->filter, filter);
+ rs->filter=g_strdup(filter);
} else {
rs->filter=NULL;
}
}
rs=g_malloc(sizeof(radiusstat_t));
- rs->filter=g_malloc(strlen(filter)+1);
- strcpy(rs->filter, filter);
+ rs->filter=g_strdup(filter);
for(i=0;i<NUM_TIMESTATS;i++) {
rs->rtd[i].num=0;
rs->rtd[i].min_num=0;
rs->rtd[i].max_num=0;
rs->rtd[i].min.secs=0;
- rs->rtd[i].min.nsecs=0;
- rs->rtd[i].max.secs=0;
- rs->rtd[i].max.nsecs=0;
- rs->rtd[i].tot.secs=0;
- rs->rtd[i].tot.nsecs=0;
+ rs->rtd[i].min.nsecs=0;
+ rs->rtd[i].max.secs=0;
+ rs->rtd[i].max.nsecs=0;
+ rs->rtd[i].tot.secs=0;
+ rs->rtd[i].tot.nsecs=0;
}
rs->open_req_num=0;
rs->program=program;
rs->version=version;
if(filter){
- rs->filter=g_malloc(strlen(filter)+1);
- strcpy(rs->filter, filter);
+ rs->filter=g_strdup(filter);
} else {
rs->filter=NULL;
}
}
hs = g_malloc(sizeof(sctpstat_t));
- hs->filter=g_malloc(strlen(filter)+1);
+ hs->filter=g_strdup(filter);
hs->ep_list = NULL;
hs->number_of_packets = 0;
- strcpy(hs->filter, filter);
sctpstat_reset(hs);
ss=g_malloc(sizeof(smbstat_t));
if(filter){
- ss->filter=g_malloc(strlen(filter)+1);
- strcpy(ss->filter, filter);
+ ss->filter=g_strdup(filter);
} else {
ss->filter=NULL;
}
sp->num_pdus = 16;
sp->pdu_stats=g_malloc( (sp->num_pdus+1) * sizeof( wsp_pdu_t) );
if(filter){
- sp->filter=g_malloc(strlen(filter)+1);
- strcpy(sp->filter,filter);
+ sp->filter=g_strdup(filter);
} else {
sp->filter=NULL;
}
return dir;
}
else {
- newdir = g_malloc(len + 2);
- strcpy(newdir, dir);
- strcat(newdir, G_DIR_SEPARATOR_S);
+ newdir = g_strdup_printf("%s%s", dir, G_DIR_SEPARATOR_S);
return newdir;
}
}
int old_umask;
int tmp_fd;
+ g_snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
if (namebuflen < namelen) {
- /* Stick in a truncated name, so that if this error is
+ /* Stick with the truncated name, so that if this error is
reported with the file name, you at least get
something. */
- g_snprintf(namebuf, namebuflen, "%s%s%s", dir, pfx, suffix);
errno = ENAMETOOLONG;
return -1;
}
- strcpy(namebuf, dir);
- strcat(namebuf, pfx);
- strcat(namebuf, suffix);
/* The Single UNIX Specification doesn't say that "mkstemp()"
creates the temporary file with mode rw-------, so we
if (toklen != 0) {
if (packet_preamble_len + toklen > PACKET_PREAMBLE_MAX_LEN)
return; /* no room to add the token to the preamble */
- strcpy(&packet_preamble[packet_preamble_len], str);
+ strncpy(&packet_preamble[packet_preamble_len], str, PACKET_PREAMBLE_MAX_LEN - packet_preamble_len);
packet_preamble_len += toklen;
if (debug >= 2) {
char *c;
char xs[PACKET_PREAMBLE_MAX_LEN];
- strcpy(xs, packet_preamble);
+ strncpy(xs, packet_preamble, PACKET_PREAMBLE_MAX_LEN);
while ((c = strchr(xs, '\r')) != NULL) *c=' ';
fprintf (stderr, "[[append_to_preamble: \"%s\"]]", xs);
}
ftenum_t dissector_table_selector_type;
struct protocol_name_search user_protocol_name;
-/* The following code will allocate and copy the command-line options in a string pointed by decoded_param */
+ /* The following code will allocate and copy the command-line options in a string pointed by decoded_param */
g_assert(cl_param);
- decoded_param = g_malloc( sizeof(gchar) * (strlen(cl_param) + 1) ); /* Allocate enough space to have a working copy of the command-line parameter */
+ decoded_param = g_strdup(cl_param);
g_assert(decoded_param);
- strcpy(decoded_param, cl_param);
/* The lines below will parse this string (modifying it) to extract all
/*
* Now construct the string.
*/
- strcpy(argstring, "");
+ argstring[0] = '\0';
i = optind;
for (;;) {
- strcat(argstring, argv[i]);
+ strncat(argstring, argv[i], len - strlen(argstring));
i++;
if (i == argc)
break;
- strcat(argstring, " ");
+ strncat(argstring, " ", len - strlen(argstring));
}
return argstring;
}
char timestamp_string[32];
gint64 *pkey = NULL;
- sprintf(timestamp_string, "%d.%04d", seconds, useconds/100);
+ g_snprintf(timestamp_string, 32, "%d.%04d", seconds, useconds/100);
/* All packets go to Catapult DCT2000 stub dissector */
wth->phdr.pkt_encap = WTAP_ENCAP_CATAPULT_DCT2000;
int n;
int stub_offset = 0;
char timestamp_string[32];
- sprintf(timestamp_string, "%d.%04d", seconds, useconds/100);
+ g_snprintf(timestamp_string, 32, "%d.%04d", seconds, useconds/100);
/* Make sure all packets go to catapult dct2000 dissector */
wth->phdr.pkt_encap = WTAP_ENCAP_CATAPULT_DCT2000;
time(&system_time);
current_time = localtime(&system_time);
memset(&comment, 0x00, sizeof(comment));
- sprintf(comment, "This capture was saved from Wireshark on %s", asctime(current_time));
+ g_snprintf(comment, 64, "This capture was saved from Wireshark on %s", asctime(current_time));
/* create the file header */
if (fseek(wdh->fh, 0, SEEK_SET) == -1) {
return FALSE;
}
memset(&file_header, 0x00, sizeof(capture_file_header));
- strcpy(file_header.observer_version, network_instruments_magic);
+ strncpy(file_header.observer_version, network_instruments_magic, 32);
file_header.offset_to_first_packet = sizeof(capture_file_header) + sizeof(tlv_header) + strlen(comment);
file_header.offset_to_first_packet = GUINT16_TO_LE(file_header.offset_to_first_packet);
file_header.number_of_information_elements = 1;
vfile_hdr.max_length = htoles(65535);
vfile_hdr.file_flags = htoles(1); /* indexes are present */
vfile_hdr.file_version = htoles(1);
- strcpy(vfile_hdr.description, "Wireshark file");
+ strncpy(vfile_hdr.description, "Wireshark file", 64);
/* Translate the encapsulation type */
switch (wdh->encap)
#ifdef HAVE_LIBZ
if (err >= WTAP_ERR_ZLIB_MIN && err <= WTAP_ERR_ZLIB_MAX) {
/* Assume it's a zlib error. */
- sprintf(errbuf, "Uncompression error: %s",
+ g_snprintf(errbuf, 128, "Uncompression error: %s",
zError(err - WTAP_ERR_ZLIB));
return errbuf;
}
#endif
wtap_errlist_index = -1 - err;
if (wtap_errlist_index >= WTAP_ERRLIST_SIZE) {
- sprintf(errbuf, "Error %d", err);
+ g_snprintf(errbuf, 128, "Error %d", err);
return errbuf;
}
if (wtap_errlist[wtap_errlist_index] == NULL)