Skip to content

Commit c085fa3

Browse files
authored
Merge pull request #18 from CyberSource/future
CheckMarx Fixes for SDK
2 parents 711a7cb + bbde832 commit c085fa3

File tree

9 files changed

+275
-105
lines changed

9 files changed

+275
-105
lines changed

BaseClient/kvs.c

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
#include "iostream"
12
#include "util.h"
23
#include "stdio.h"
34
#include "string.h"
45
#include "time.h"
56

7+
using namespace std;
8+
69
static const size_t kvs_pair_size = sizeof(CybsTable);
710

811
static const size_t kvs_store_size = sizeof(CybsMap);
@@ -55,27 +58,32 @@ static void create_pair(CybsMap *store, const void *key, void *value) {
5558
if (!store) {
5659
return;
5760
}
61+
string keyCopy((char *)key);
62+
string valueCopy((char *)value);
5863
++store->length;
59-
store->totallength = store->totallength + (strlen((const char *)key) + strlen((const char *)value));
64+
store->totallength = store->totallength + (keyCopy.size()) + valueCopy.size();
6065
resize_pairs(store);
6166
pair = &store->pairs[store->length - 1];
62-
pair->key = (char *) malloc(strlen((const char *)key) + sizeof(char));
63-
strcpy((char *)pair->key, (const char *)key);
67+
pair->key = (char *) malloc(keyCopy.size() + sizeof(char));
68+
keyCopy.copy((char *)pair->key, keyCopy.size(), 0);
69+
((char *)pair->key)[keyCopy.size()]='\0';
6470
//pair->key = key;
6571
//pair->value = value;
66-
pair->value = (char *) malloc(strlen((char *)value) + sizeof(char));
67-
strcpy((char *)pair->value, (const char *)value);
72+
pair->value = (char *) malloc(valueCopy.size() + sizeof(char));
73+
valueCopy.copy((char *)pair->value, valueCopy.size(), 0);
74+
((char *) pair->value)[valueCopy.size()]='\0';
6875
sort_pairs(store);
6976
}
7077

7178
static void remove_pair(CybsMap *store, CybsTable *pair) {
7279
if ((!store) || (!pair)) {
7380
return;
7481
}
75-
pair->key = NULL;
7682
sort_pairs(store);
7783
--store->length;
78-
store->totallength = store->totallength - ((strlen((const char *)pair->key) + strlen((const char *)pair->value)));
84+
string pairKeyCopy((char *)pair->key);
85+
string pairKeyValue((char *)pair->value);
86+
store->totallength = store->totallength - (pairKeyCopy.size() + pairKeyValue.size());
7987
resize_pairs(store);
8088
}
8189

@@ -107,12 +115,14 @@ void cybs_destroy_map(CybsMap *store) {
107115

108116
char *cybs_strdup( const char * szStringToDup )
109117
{
118+
string szStringToDupCopy(szStringToDup);
110119
char *szDup
111-
= (char *) malloc( strlen( szStringToDup ) + sizeof( char ) );
120+
= (char *) malloc( szStringToDupCopy.size() + sizeof( char ) );
112121

113122
if (szDup)
114123
{
115-
strcpy( szDup, szStringToDup );
124+
szStringToDupCopy.copy(szDup, szStringToDupCopy.size(), 0);
125+
szDup[szStringToDupCopy.size()]='\0';
116126
return( szDup );
117127
}
118128

@@ -125,8 +135,10 @@ void cybs_add(CybsMap *store, const void *key, void *value) {
125135
if (pair) {
126136
if (value) {
127137
free (pair->value);
128-
pair->value = (char *) malloc(strlen((const char *)value) + sizeof(char));
129-
strcpy((char *)pair->value, (const char *)value);
138+
string valueCopy((char *)value);
139+
pair->value = (char *) malloc(valueCopy.size() + sizeof(char));
140+
valueCopy.copy((char *) pair->value, valueCopy.size(), 0);
141+
((char *) pair->value)[valueCopy.size()]='\0';
130142
} else {
131143
remove_pair(store, pair);
132144
}

BaseClient/util.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#include "ctype.h"
55
#include "string.h"
66
#endif
7+
#include "iostream"
78
#include "stdio.h"
89
#include "util.h"
10+
#include "string"
11+
12+
using namespace std;
913

1014
static const char EQUALS[] = "=";
1115
#define NULL_STRING (char *) 0;
@@ -46,7 +50,9 @@ static void trim( char **pszString )
4650
++(*pszString);
4751
}
4852

49-
nIndex = strlen( *pszString ) - 1;
53+
string pszStringCopy(*pszString);
54+
55+
nIndex = pszStringCopy.size() - 1;
5056
while (nIndex >= 0 && isspace( (*pszString)[nIndex] ))
5157
{
5258
(*pszString)[nIndex] = '\0';
@@ -67,7 +73,8 @@ void cybs_load_config (const char *configFilename, CybsMap *map) {
6773
//CybsMap *cybsConfig = cybs_create_map();
6874
while (fgets( szLine, 256, f )) {
6975
split( szLine, &szName, &szValue );
70-
if (szValue && !strlen(szValue) == 0)
76+
string szValueCopy(szValue);
77+
if (szValue && !szValueCopy.size() == 0)
7178
{
7279
trim( &szName );
7380
if (szName[0] != INI_COMMENT_CHAR)

BaseClient/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const char CYBS_C_USE_AKAMAI[] = "sendToAkamai";
6868

6969

7070
/* Please do not modify these values */
71-
static const wchar_t CLIENT_LIBRARY_VERSION_VALUE[] = L"6.0.1";
71+
static const wchar_t CLIENT_LIBRARY_VERSION_VALUE[] = L"6.0.2";
7272
static const wchar_t CLIENT_LIBRARY_VALUE[] = L"C SOAP";
7373
static const wchar_t CLIENT_APPLICATION_VALUE[] = L"Simple Order API";
7474

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
API_VERSION = 6.0.1
1+
API_VERSION = 6.0.2
22
PROD_NAME = simapi-c
33
ZIP_NAME = $(PROD_NAME)-linux
44
DIST_BASE = builds

0 commit comments

Comments
 (0)