Commit d2b823a8 authored by Matteo Quintiliani's avatar Matteo Quintiliani

Substitude strcpy() with strncpy()


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1229 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 5e694902
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.h,v 1.52 2008-04-22 12:53:42 mtheo Exp $
* $Id: nmxp.h,v 1.53 2009-03-10 16:36:25 mtheo Exp $
*
*/
......@@ -999,9 +999,11 @@ typedef enum {
} NMXP_BUFFER_FLAG;
#define NMXP_MAX_SIZE_USERNAME 12
/*! \brief Body of ConnectRequest message*/
typedef struct {
char username[12];
char username[NMXP_MAX_SIZE_USERNAME];
int32_t version;
int32_t connection_time;
int32_t crc32;
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_chan.h,v 1.24 2008-07-21 22:41:24 mtheo Exp $
* $Id: nmxp_chan.h,v 1.25 2009-03-10 16:36:25 mtheo Exp $
*
*/
......@@ -16,6 +16,8 @@
#include <stdint.h>
#define NMXP_CHAN_MAX_SIZE_STR_PATTERN 20
/*! \brief Channel list */
typedef struct NMXP_META_CHAN_LIST {
int32_t key;
......@@ -37,10 +39,12 @@ typedef enum {
/*! \brief Max number of channels */
#define MAX_N_CHAN 2000
#define NMXP_CHAN_MAX_SIZE_NAME 24
/*! \brief The key/name info for one channel */
typedef struct {
int32_t key;
char name[24];
char name[NMXP_CHAN_MAX_SIZE_NAME];
} NMXP_CHAN_KEY_NET;
/*! \brief Channel list */
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.c,v 1.89 2008-04-22 12:53:42 mtheo Exp $
* $Id: nmxp.c,v 1.90 2009-03-10 16:36:25 mtheo Exp $
*
*/
......@@ -187,7 +187,7 @@ int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, in
while(split_channelList.number < n_channel && i < channelList->number) {
split_channelList.channel[split_channelList.number].key = channelList->channel[i].key;
/* Not necessary, but it could help for debugging */
strcpy(split_channelList.channel[split_channelList.number].name, channelList->channel[i].name);
strncpy(split_channelList.channel[split_channelList.number].name, channelList->channel[i].name, NMXP_CHAN_MAX_SIZE_NAME);
split_channelList.number++;
i++;
}
......@@ -258,7 +258,7 @@ int nmxp_sendConnectRequest(int isock, char *naqs_username, char *naqs_password,
connectRequest.username[i] = 0;
}
if(naqs_username_length != 0) {
strcpy(connectRequest.username, naqs_username);
strncpy(connectRequest.username, naqs_username, NMXP_MAX_SIZE_USERNAME);
}
connectRequest.version = protocol_version;
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.c,v 1.76 2009-01-29 20:33:15 mtheo Exp $
* $Id: nmxp_base.c,v 1.77 2009-03-10 16:36:25 mtheo Exp $
*
*/
......@@ -463,9 +463,9 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da
int idx;
static int32_t outdata[MAX_OUTDATA];
char station_code[20];
char channel_code[20];
char network_code[20];
char station_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char *nmxp_channel_name = NULL;
static NMXP_DATA_PROCESS pd;
......@@ -506,9 +506,9 @@ NMXP_DATA_PROCESS *nmxp_processDecompressedData(char* buffer_data, int length_da
pd.key = pKey;
if(network_code[0] != 0) {
strcpy(pd.network, network_code);
strncpy(pd.network, network_code, NETWORK_LENGTH);
} else {
strcpy(pd.network, network_code_default);
strncpy(pd.network, network_code_default, NETWORK_LENGTH);
}
if(station_code[0] != 0) {
strncpy(pd.station, station_code, STATION_LENGTH);
......@@ -546,9 +546,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
int32_t pSampRate = 0;
int32_t *pDataPtr = NULL;
char station_code[20];
char channel_code[20];
char network_code[20];
char station_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
static NMXP_DATA_PROCESS pd;
......@@ -697,9 +697,9 @@ NMXP_DATA_PROCESS *nmxp_processCompressedData(char* buffer_data, int length_data
pd.key = pKey;
if(network_code[0] != 0) {
strcpy(pd.network, network_code);
strncpy(pd.network, network_code, NETWORK_LENGTH);
} else {
strcpy(pd.network, network_code_default);
strncpy(pd.network, network_code_default, NETWORK_LENGTH);
}
if(station_code[0] != 0) {
strncpy(pd.station, station_code, STATION_LENGTH);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_chan.c,v 1.42 2009-01-29 13:10:49 mtheo Exp $
* $Id: nmxp_chan.c,v 1.43 2009-03-10 16:36:25 mtheo Exp $
*
*/
......@@ -52,14 +52,14 @@ int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *statio
/* NET.STA.CHAN */
*period1++ = '\0';
*period2++ = '\0';
strcpy(network_code, tmp_name);
strcpy(station_code, period1);
strcpy(channel_code, period2);
strncpy(network_code, tmp_name, NMXP_CHAN_MAX_SIZE_STR_PATTERN);
strncpy(station_code, period1, NMXP_CHAN_MAX_SIZE_STR_PATTERN);
strncpy(channel_code, period2, NMXP_CHAN_MAX_SIZE_STR_PATTERN);
} else {
/* STA.CHAN */
*period1++ = '\0';
strcpy(station_code, tmp_name);
strcpy(channel_code, period1);
strncpy(station_code, tmp_name, NMXP_CHAN_MAX_SIZE_STR_PATTERN);
strncpy(channel_code, period1, NMXP_CHAN_MAX_SIZE_STR_PATTERN);
}
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CHANNEL, "Name %s is not in NET.STA.CHAN format! (NET. is optional)\n",
......@@ -80,7 +80,6 @@ int nmxp_chan_cpy_sta_chan(const char *net_dot_station_dot_channel, char *statio
}
/*
* Match string against the extended regular expression in
* pattern, treating errors as no match.
......@@ -91,10 +90,10 @@ int nmxp_chan_match(const char *net_dot_station_dot_channel, char *pattern)
{
int ret = 0;
int i, l;
char sta_pattern[20];
char cha_pattern[20];
char net_pattern[20];
char sta_sdc[20];
char sta_pattern[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char cha_pattern[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char net_pattern[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char sta_sdc[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char *cha_sdc;
/* validate pattern channel */
......@@ -163,7 +162,7 @@ int nmxp_chan_match(const char *net_dot_station_dot_channel, char *pattern)
i++;
}
strcpy(sta_sdc, net_dot_station_dot_channel);
strncpy(sta_sdc, net_dot_station_dot_channel, NMXP_CHAN_MAX_SIZE_STR_PATTERN);
if( (cha_sdc = strchr(sta_sdc, '.')) == NULL ) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CHANNEL, "Channel %s is not in STA.CHAN format!\n",
NMXP_LOG_STR(net_dot_station_dot_channel));
......@@ -232,14 +231,14 @@ int nmxp_chan_lookupKeyIndex(int32_t key, NMXP_CHAN_LIST_NET *channelList)
char *nmxp_chan_lookupName(int32_t key, NMXP_CHAN_LIST_NET *channelList)
{
int i_chan = 0;
static char ret[15];
static char ret[NMXP_CHAN_MAX_SIZE_NAME];
ret[0] = 0;
for (i_chan = 0; i_chan < channelList->number; i_chan++)
{
if ( key == channelList->channel[i_chan].key ) {
strcpy(ret, channelList->channel[i_chan].name);
strncpy(ret, channelList->channel[i_chan].name, NMXP_CHAN_MAX_SIZE_NAME);
}
}
......@@ -264,7 +263,7 @@ NMXP_CHAN_LIST *nmxp_chan_getType(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE dat
{
if ( getDataTypeFromKey(channelList->channel[i_chan].key) == dataType) {
ret_channelList->channel[ret_channelList->number].key = channelList->channel[i_chan].key;
strcpy(ret_channelList->channel[ret_channelList->number].name, channelList->channel[i_chan].name);
strncpy(ret_channelList->channel[ret_channelList->number].name, channelList->channel[i_chan].name, NMXP_CHAN_MAX_SIZE_NAME);
ret_channelList->number++;
}
}
......@@ -278,9 +277,9 @@ NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE
int istalist, ista;
char sta_chan_code_pattern[100];
int i_chan, ret_match;
char network_code[20];
char station_code[20];
char channel_code[20];
char network_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char station_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
char channel_code[NMXP_CHAN_MAX_SIZE_STR_PATTERN];
int i_chan_found = -1;
int i_chan_duplicated = -1;
char *nmxp_channel_name = NULL;
......@@ -319,7 +318,7 @@ NMXP_CHAN_LIST_NET *nmxp_chan_subset(NMXP_CHAN_LIST *channelList, NMXP_DATATYPE
/* Add channel */
i_chan_found = i_chan;
ret_channelList->channel[ret_channelList->number].key = channelList->channel[i_chan_found].key;
strcpy(ret_channelList->channel[ret_channelList->number].name, channelList->channel[i_chan_found].name);
strncpy(ret_channelList->channel[ret_channelList->number].name, channelList->channel[i_chan_found].name, NMXP_CHAN_MAX_SIZE_NAME);
nmxp_chan_cpy_sta_chan(sta_chan_code_pattern, station_code, channel_code, network_code);
sprintf(ret_channelList->channel[ret_channelList->number].name, "%s.%s",
(network_code[0] != 0)? network_code : network_code_default, channelList->channel[i_chan_found].name);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_log.c,v 1.20 2008-04-11 07:50:32 mtheo Exp $
* $Id: nmxp_log.c,v 1.21 2009-03-10 16:36:25 mtheo Exp $
*
*/
......@@ -132,13 +132,14 @@ void nmxp_log_print_all(char *message, int (*a_func_log[NMXP_MAX_FUNC_LOG]) (cha
}
}
#define MAX_SIZE_TIMESTR 100
int nmxp_log(int level, int verb, ... )
{
static int staticverb = 0;
int retvalue = 0;
char message[MAX_LOG_MESSAGE_LENGTH];
char message_final[MAX_LOG_MESSAGE_LENGTH];
char timestr[100];
char timestr[MAX_SIZE_TIMESTR];
char *format;
va_list listptr;
time_t loc_time;
......@@ -154,7 +155,7 @@ int nmxp_log(int level, int verb, ... )
/* Build local time string and cut off the newline */
time(&loc_time);
/* TODO*/
strcpy(timestr, asctime(localtime(&loc_time)));
strncpy(timestr, asctime(localtime(&loc_time)), MAX_SIZE_TIMESTR);
timestr[strlen(timestr) - 1] = '\0';
retvalue = vsnprintf(message, MAX_LOG_MESSAGE_LENGTH, format, listptr);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_win.c,v 1.2 2008-02-19 14:40:20 mtheo Exp $
* $Id: nmxp_win.c,v 1.3 2009-03-10 16:36:25 mtheo Exp $
*
*/
......@@ -124,17 +124,18 @@ static struct ErrorEntry {
const int kNumMessages = sizeof(gaErrorList) / sizeof(struct ErrorEntry);
#define MAX_SIZE_acErrorBuffer 2048
char* WSAGetLastErrorMessage(int nErrorID)
{
static char acErrorBuffer[2048];
static char acErrorBuffer[MAX_SIZE_acErrorBuffer];
int i = 0;
while(i < kNumMessages && gaErrorList[i].nID != nErrorID) {
i++;
}
if(i < kNumMessages) {
strcpy(acErrorBuffer, gaErrorList[i].pcMessage);
strncpy(acErrorBuffer, gaErrorList[i].pcMessage, MAX_SIZE_acErrorBuffer);
} else {
strcpy(acErrorBuffer, "Unknown error");
strncpy(acErrorBuffer, "Unknown error", MAX_SIZE_acErrorBuffer);
}
return acErrorBuffer;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment