Permalink
Browse files

0002700: C Client doesn't properly parse quote characters in incoming

data.
  • Loading branch information...
mmichalek committed Jul 29, 2016
1 parent d9d57e3 commit 76ad09226d2e7c8a8f0d82c295d72edfe906d9bd
@@ -5,11 +5,24 @@
<stringAttribute key="org.eclipse.cdt.debug.mi.core.GDB_INIT" value=".gdbinit"/>
<stringAttribute key="org.eclipse.cdt.debug.mi.core.commandFactory" value="org.eclipse.cdt.debug.mi.core.standardLinuxCommandFactory"/>
<booleanAttribute key="org.eclipse.cdt.debug.mi.core.verboseMode" value="false"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="org.eclipse.cdt.debug.mi.core.CDebuggerNew"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB" value="true"/>
<listAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB_LIST"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="gdb"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_ON_FORK" value="false"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.GDB_INIT" value=".gdbinit"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.REVERSE" value="false"/>
<listAttribute key="org.eclipse.cdt.dsf.gdb.SOLIB_PATH"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.TRACEPOINT_MODE" value="TP_NORMAL_ONLY"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.internal.ui.launching.LocalApplicationCDebuggerTab.DEFAULTS_SET" value="true"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="gdb"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="run"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/symclient_test"/>
<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug (Linux)/symclient_test"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="symmetric-client-clib-test"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="cdt.managedbuild.config.gnu.exe.debug.2121908870"/>
@@ -20,8 +33,7 @@
<listEntry value="4"/>
</listAttribute>
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
<mapEntry key="DYLD_LIBRARY_PATH" value="/usr/local/lib:/usr/lib:../symmetric-client-clib/Debug:/usr/local/lib"/>
<mapEntry key="LD_LIBRARY_PATH" value="../symmetric-client-clib/Debug:/usr/local/lib"/>
<mapEntry key="LD_LIBRARY_PATH" value="../symmetric-client-clib/Debug (Linux):/usr/local/lib"/>
</mapAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
@@ -30,9 +30,9 @@ int main() {
//SymMapTest_CUnit() != CUE_SUCCESS ||
//SymListTest_CUnit() != CUE_SUCCESS ||
//SymStringBuilderTest_CUnit() != CUE_SUCCESS ||
SymStringArrayTest_CUnit() != CUE_SUCCESS ||
//SymStringArrayTest_CUnit() != CUE_SUCCESS ||
//SymPropertiesTest_CUnit() != CUE_SUCCESS ||
//SymStringUtilsTest_CUnit() != CUE_SUCCESS ||
SymStringUtilsTest_CUnit() != CUE_SUCCESS ||
//SymHexTest_CUnit() != CUE_SUCCESS ||
//SymBase64Test_CUnit() != CUE_SUCCESS ||
1==0) {
@@ -125,6 +125,22 @@ void SymStringUtilsTest_test_substring() {
CU_ASSERT(strcmp(SymStringUtils_substring("Testing", 0, 8), "Testing") == 0);
}
void SymStringUtilsTest_test_replace() {
CU_ASSERT(strcmp(SymStringUtils_replaceWithLength("", strlen(""), "H", "Tr"), "") == 0);
CU_ASSERT(strcmp(SymStringUtils_replaceWithLength("Hello", strlen("Hello"), "H", "Tr"), "Trello") == 0);
CU_ASSERT(strcmp(SymStringUtils_replaceWithLength("\\\"Hi\\\"", strlen("\\\"Hi\\\""), "\\\"", "\"\""),
"\"\"Hi\"\"") == 0);
CU_ASSERT(strcmp(SymStringUtils_replaceWithLength(",", strlen(","), ",", "||"), "||") == 0);
CU_ASSERT(strcmp(SymStringUtils_replaceWithLength(" spaces ", strlen(" spaces "), " ", "|longer|"), "|longer|spaces|longer|") == 0);
CU_ASSERT(strcmp(SymStringUtils_replace("", "H", "Tr"), "") == 0);
CU_ASSERT(strcmp(SymStringUtils_replace("Hello", "H", "Tr"), "Trello") == 0);
CU_ASSERT(strcmp(SymStringUtils_replace("\\\"Hi\\\"", "\\\"", "\"\""), "\"\"Hi\"\"") == 0);
CU_ASSERT(strcmp(SymStringUtils_replace(",", ",", "||"), "||") == 0);
CU_ASSERT(strcmp(SymStringUtils_replace(" spaces ", " ", "|longer|"), "|longer|spaces|longer|") == 0);
}
void SymStringUtilsTest_test_startsWith() {
CU_ASSERT(SymStringUtils_startsWith("Testing","Tes") == 1);
CU_ASSERT(SymStringUtils_startsWith("Testing","Ttt") == 0);
@@ -160,6 +176,8 @@ int SymStringUtilsTest_CUnit() {
CU_add_test(suite, "SymStringUtilsTest_testRTrim", SymStringUtilsTest_testRTrim) == NULL ||
CU_add_test(suite, "SymStringUtilsTest_test_startsWith", SymStringUtilsTest_test_startsWith) == NULL ||
CU_add_test(suite, "SymStringUtilsTest_test_endsWith", SymStringUtilsTest_test_endsWith) == NULL ||
CU_add_test(suite, "SymStringUtilsTest_test_replace", SymStringUtilsTest_test_replace) == NULL ||
1==0) {
return CUE_NOTEST;
}
@@ -26,6 +26,7 @@
#include <string.h>
#include <curl/curl.h>
#include <csv.h>
#include "common/Log.h"
#include "io/data/DataProcessor.h"
#include "io/writer/DataWriter.h"
#include "model/Node.h"
@@ -34,6 +35,7 @@
#include "util/Map.h"
#include "io/data/CsvConstants.h"
#include "io/data/CsvData.h"
#include "util/StringUtils.h"
typedef struct SymProtocolDataReader {
SymDataProcessor super;
@@ -37,6 +37,8 @@ char* SymStringUtils_format(char *format, ...);
unsigned short SymStringUtils_equals(char *str1, char *str2);
unsigned short SymStringUtils_equalsIgnoreCase(char *str1, char *str2);
char * SymStringUtils_substring(char *str, int startIndex, int endIndex);
char * SymStringUtils_replace(char *str, char *searchFor, char* replaceWith);
char * SymStringUtils_replaceWithLength(char *str, size_t length, char *searchFor, char* replaceWith);
void SymStringUtils_replaceChar(char *str, char oldChar, char newChar);
unsigned short SymStringUtils_startsWith(char *str, char *suffix);
unsigned short SymStringUtils_endsWith(char *str, char *suffix);
@@ -19,7 +19,6 @@
* under the License.
*/
#include "io/reader/ProtocolDataReader.h"
#include "common/Log.h"
static void SymProtocolDataReader_parseField(void *data, size_t size, void *userData) {
SymProtocolDataReader *this = (SymProtocolDataReader *) userData;
@@ -118,11 +117,23 @@ void SymProtocolDataReader_open(SymProtocolDataReader *this) {
size_t SymProtocolDataReader_process(SymProtocolDataReader *this, char *data, size_t size, size_t count) {
size_t length = size * count;
if (csv_parse(this->csvParser, data, length, SymProtocolDataReader_parseField, SymProtocolDataReader_parseLine, this) != length) {
SymLog_error("Error from CSV parser: %s", csv_strerror(csv_error(this->csvParser)));
return 0;
char * dataWithReplacedQuotes = SymStringUtils_replace(data, "\\\"", "\"\"");
size_t resultLength = csv_parse(this->csvParser, dataWithReplacedQuotes, length,
SymProtocolDataReader_parseField, SymProtocolDataReader_parseLine, this);
int rc = length;
if (resultLength != length) {
SymLog_error("Error from CSV parser: %s", csv_strerror(csv_error(this->csvParser)));
rc = 0;
}
return length;
if (dataWithReplacedQuotes) {
free(dataWithReplacedQuotes);
}
return rc;
}
SymList * SymProtocolDataReader_getBatchesProcessed(SymProtocolDataReader *this) {
@@ -42,7 +42,7 @@ char *SymStringUtils_trim(char *str)
}
int newLength = length - leadingWhitespaces - trailingWhitespaces;
char *newString = malloc(newLength+1);
char *newString = malloc((newLength+1)*sizeof(char));
int i;
for (i = leadingWhitespaces; i < length-trailingWhitespaces; i++) {
@@ -57,22 +57,22 @@ char *SymStringUtils_trim(char *str)
char *SymStringUtils_ltrim(char *str) {
int length = strlen(str);
int leadingWhitespaces = 0;
while (isspace(str[leadingWhitespaces]) && leadingWhitespaces < length) {
leadingWhitespaces++;
}
int leadingWhitespaces = 0;
while (isspace(str[leadingWhitespaces]) && leadingWhitespaces < length) {
leadingWhitespaces++;
}
int newLength = length - leadingWhitespaces;
char *newString = malloc(newLength+1);
int newLength = length - leadingWhitespaces;
char *newString = malloc((newLength+1)*sizeof(char));
int i;
for (i = leadingWhitespaces; i < length; i++) {
newString[i-leadingWhitespaces] = str[i];
}
int i;
for (i = leadingWhitespaces; i < length; i++) {
newString[i-leadingWhitespaces] = str[i];
}
newString[i] = '\0';
newString[newLength] = '\0';
return newString;
return newString;
}
char *SymStringUtils_rtrim(char *str) {
@@ -86,7 +86,7 @@ char *SymStringUtils_rtrim(char *str) {
trailingWhitespaces = ((length-1)-trailingWhitespaces);
int newLength = length - trailingWhitespaces;
char *newString = malloc(newLength+1);
char *newString = malloc((newLength+1)*sizeof(char));
int i;
for (i = 0; i < length-trailingWhitespaces; i++) {
@@ -101,7 +101,7 @@ char *SymStringUtils_rtrim(char *str) {
char *SymStringUtils_toUpperCase(char *str) {
int length = strlen(str);
char *newString = malloc(length+1);
char *newString = malloc((length+1)*sizeof(char));
int i;
for (i = 0; i < length; i++) {
@@ -115,7 +115,7 @@ char *SymStringUtils_toUpperCase(char *str) {
char *SymStringUtils_toLowerCase(char *str) {
int length = strlen(str);
char *newString = malloc(length+1);
char *newString = malloc((length+1)*sizeof(char));
int i;
for (i = 0; i < length; i++) {
@@ -171,6 +171,38 @@ char * SymStringUtils_substring(char *str, int startIndex, int endIndex) {
return value;
}
char * SymStringUtils_replaceWithLength(char *str, size_t length, char *searchFor, char* replaceWith) {
int searchLength = strlen(searchFor);
int replaceLength = strlen(replaceWith);
int replaceCount = 0;
char *index = strstr(str, searchFor);
while (index) {
replaceCount++;
index += searchLength;
index = strstr(index, searchFor);
}
char *newString = malloc(sizeof(char) * (length+(replaceCount*(replaceLength-searchLength))));
char *newStringFinal = newString; // remember original pointer.
int i;
for (i = 0; i < replaceCount; ++i) {
index = strstr(str, searchFor);
int leadingChars = index - str;
newString = strncpy(newString, str, leadingChars) + leadingChars;
newString = strcpy(newString, replaceWith) + replaceLength;
str += leadingChars + searchLength; // move the pointer to the end of this replacement.
}
strcpy(newString, str); // get remaining chars at the end.
return newStringFinal;
}
char * SymStringUtils_replace(char *str, char *searchFor, char* replaceWith) {
return SymStringUtils_replaceWithLength(str, strlen(str), searchFor, replaceWith);
}
unsigned short SymStringUtils_equals(char *str1, char *str2) {
if (str1 == NULL && str2 == NULL) {
return 1;
@@ -225,3 +257,5 @@ unsigned short SymStringUtils_endsWith(char *str, char *suffix) {
}
Oops, something went wrong.

0 comments on commit 76ad092

Please sign in to comment.