Skip to content
This repository was archived by the owner on Sep 13, 2020. It is now read-only.

Commit fcad89a

Browse files
author
Franci Penov
committed
Misc bug fixes
1 parent d40dc03 commit fcad89a

File tree

9 files changed

+111
-82
lines changed

9 files changed

+111
-82
lines changed

cc3200/samples/blink/blink.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ void blinkGetInstallationObjectId() {
5050

5151
// Encode the query parameter value
5252
char content[150];
53-
sprintf(content, "{\"installationId\": \"%s\"}", g_InstallationID);
53+
snprintf(content, sizeof(content)-1, "{\"installationId\": \"%s\"}", g_InstallationID);
5454

5555
char encodedContent[150];
5656
memset(encodedContent, 0, sizeof(encodedContent));
5757
urlEncode(content, encodedContent);
5858

5959
memset(content, 0, sizeof(content));
60-
sprintf(content, "where=%s", encodedContent);
60+
snprintf(content, sizeof(content)-1, "where=%s", encodedContent);
6161

6262
parseSendRequest((ParseClient)parseClient, "GET", "/1/installations", content, blinkGetInstallationObjectIdByIdCallback);
6363
}
@@ -79,14 +79,14 @@ void blinkGetModelObjectId() {
7979

8080
// Encode the query parameter value
8181
char content[150];
82-
sprintf(content, "{\"appName\": \"fbdr000001a\"}");
82+
snprintf(content, sizeof(content)-1, "{\"appName\": \"fbdr000001a\"}");
8383

8484
char encodedContent[150];
8585
memset(encodedContent, 0, sizeof(encodedContent));
8686
urlEncode(content, encodedContent);
8787

8888
memset(content, 0, sizeof(content));
89-
sprintf(content, "where=%s", encodedContent);
89+
snprintf(content, sizeof(content)-1, "where=%s", encodedContent);
9090

9191
parseSendRequest((ParseClient)parseClient, "GET", "/1/classes/Model", content, blinkGetModelObjectIdByNameCallback);
9292
}
@@ -120,10 +120,10 @@ void blinkUpdateInstallation() {
120120

121121
char path[40];
122122
memset(path, 0, sizeof(path));
123-
sprintf(path, "/1/installations/%s", installationObjectId);
123+
snprintf(path, sizeof(path)-1, "/1/installations/%s", installationObjectId);
124124

125125
memset(objectJson, 0, sizeof(objectJson));
126-
sprintf(objectJson, "{\"deviceName\": \"%s\", \"deviceSubtype\": \"fluffy\", \"model\": {\"__type\":\"Pointer\",\"className\":\"Model\",\"objectId\":\"%s\"}, \"owner\": {\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"%s\"}}",
126+
snprintf(objectJson, sizeof(objectJson)-1, "{\"deviceName\": \"%s\", \"deviceSubtype\": \"fluffy\", \"model\": {\"__type\":\"Pointer\",\"className\":\"Model\",\"objectId\":\"%s\"}, \"owner\": {\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"%s\"}}",
127127
g_DeviceName, modelObjectId, userObjectId);
128128

129129
parseSendRequest(parseClient, "PUT", path, objectJson, blinkRequestCallback);
@@ -153,7 +153,7 @@ void saveLedState() {
153153
UART_PRINT("[Blink] Saving LED state.\r\n");
154154

155155
// TODO: Use parseGetInstallationId() instead of installationObjectId
156-
sprintf(objectJson, "{\"installationId\": \"%s\", \"value\": {\"state\": \"%s\"}, \"alarm\": true, \"ACL\":{ \"%s\": { \"read\": true, \"write\": true}}}",
156+
snprintf(objectJson, sizeof(objectJson)-1, "{\"installationId\": \"%s\", \"value\": {\"state\": \"%s\"}, \"alarm\": true, \"ACL\":{ \"%s\": { \"read\": true, \"write\": true}}}",
157157
installationObjectId, getLedState(), userObjectId);
158158
parseSendRequest(parseClient, "POST", "/1/classes/Event", objectJson, blinkRequestCallback);
159159
}

cc3200/samples/blink/network.c

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ SlSecParams_t g_SecParams;
3131

3232
#define CONNECTION_TIMEOUT_COUNT 5000
3333

34+
#define MIN(a, b) ((a > b) ? b : a)
35+
3436
void printVersionInfo() {
3537
// get the host driver version information
3638
SlVersionFull ver;
@@ -117,10 +119,12 @@ void startConfigurationMode() {
117119
sl_NetCfgGet(SL_MAC_ADDRESS_GET, NULL, &macAddressLen, (_u8 *)macAddressVal);
118120

119121
char ssid[MAXIMAL_SSID_LENGTH + 1];
120-
sprintf(ssid, "%s-%s-%02X%02X%02X", "TL04", "fbdr000001a",
121-
macAddressVal[SL_MAC_ADDR_LEN-3],
122-
macAddressVal[SL_MAC_ADDR_LEN-2],
123-
macAddressVal[SL_MAC_ADDR_LEN-1]);
122+
snprintf(ssid,
123+
sizeof(ssid)-1,
124+
"%s-%s-%02X%02X%02X", "TL04", "fbdr000001a",
125+
macAddressVal[SL_MAC_ADDR_LEN-3],
126+
macAddressVal[SL_MAC_ADDR_LEN-2],
127+
macAddressVal[SL_MAC_ADDR_LEN-1]);
124128
int ssidLen = strlen(ssid);
125129

126130
status = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, ssidLen, (unsigned char*)ssid);
@@ -281,24 +285,27 @@ void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *httpServerEvent, SlHttpSe
281285
{
282286
int tokenNameLen = httpServerEvent->EventData.httpPostData.token_name.len;
283287
char tokenName[256];
284-
memcpy(tokenName, httpServerEvent->EventData.httpPostData.token_name.data, tokenNameLen);
288+
tokenNameLen = MIN(tokenNameLen, sizeof(tokenName)-1);
289+
strncpy(tokenName, (const char *)(httpServerEvent->EventData.httpPostData.token_name.data), tokenNameLen);
285290
tokenName[tokenNameLen] = 0;
286291

287292
int tokenValueLen = httpServerEvent->EventData.httpPostData.token_value.len;
288293
char tokenValue[256];
289-
memcpy(tokenValue, httpServerEvent->EventData.httpPostData.token_value.data, tokenValueLen);
294+
tokenValueLen = MIN(tokenValueLen, sizeof(tokenValue)-1);
295+
strncpy(tokenValue, (const char *)(httpServerEvent->EventData.httpPostData.token_value.data), tokenValueLen);
290296
tokenValue[tokenValueLen] = 0;
291297

292298
UART_PRINT("[Blink] Parameter name : %s\r\n", tokenName);
293299
UART_PRINT(" Parameter value : %s\r\n", tokenValue);
294300

295-
if ((0 == memcmp(tokenName, "__SL_P_USZ", tokenNameLen))
296-
&& (0 == memcmp( tokenValue, "Add", tokenValueLen))) {
301+
if ((0 == strcmp(tokenName, "__SL_P_USZ"))
302+
&& (0 == strcmp(tokenValue, "Add"))) {
297303
g_ProvisioningDone = 1;
298-
} else if (0 == memcmp(tokenName, "__SL_P_USA", tokenNameLen)) {
299-
memcpy(g_WlanSSID, tokenValue, tokenValueLen);
304+
} else if (0 == strcmp(tokenName, "__SL_P_USA")) {
305+
tokenValueLen = MIN(tokenValueLen, sizeof(g_WlanSSID)-1);
306+
strncpy((char *)g_WlanSSID, tokenValue, tokenValueLen);
300307
g_WlanSSID[tokenValueLen] = 0;
301-
} else if (0 == memcmp(tokenName, "__SL_P_USB", tokenNameLen)) {
308+
} else if (0 == strcmp(tokenName, "__SL_P_USB")) {
302309
if (tokenValue[0] == '0') {
303310
g_SecParams.Type = SL_SEC_TYPE_OPEN;
304311
} else if (tokenValue[0] == '1') {
@@ -308,25 +315,31 @@ void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *httpServerEvent, SlHttpSe
308315
} else {
309316
g_SecParams.Type = SL_SEC_TYPE_OPEN;
310317
}
311-
} else if (0 == memcmp(tokenName, "__SL_P_USC", tokenNameLen)) {
312-
memcpy(g_WlanSecurityKey, tokenValue, tokenValueLen);
318+
} else if (0 == strcmp(tokenName, "__SL_P_USC")) {
319+
tokenValueLen = MIN(tokenValueLen, sizeof(g_WlanSecurityKey)-1);
320+
strncpy((char *)g_WlanSecurityKey, tokenValue, tokenValueLen);
313321
g_WlanSecurityKey[tokenValueLen] = 0;
314322
g_SecParams.Key = g_WlanSecurityKey;
315323
g_SecParams.KeyLen = tokenValueLen;
316-
} else if (0 == memcmp(tokenName, "__SL_P_USD", tokenNameLen)) {
317-
memcpy(g_ApplicationID, tokenValue, tokenValueLen);
324+
} else if (0 == strcmp(tokenName, "__SL_P_USD")) {
325+
tokenValueLen = MIN(tokenValueLen, sizeof(g_ApplicationID)-1);
326+
strncpy(g_ApplicationID, tokenValue, tokenValueLen);
318327
g_ApplicationID[tokenValueLen] = 0;
319-
} else if (0 == memcmp(tokenName, "__SL_P_USE", tokenNameLen)) {
320-
memcpy(g_ClientKey, tokenValue, tokenValueLen);
328+
} else if (0 == strcmp(tokenName, "__SL_P_USE")) {
329+
tokenValueLen = MIN(tokenValueLen, sizeof(g_ClientKey)-1);
330+
strncpy(g_ClientKey, tokenValue, tokenValueLen);
321331
g_ClientKey[tokenValueLen] = 0;
322-
} else if (0 == memcmp(tokenName, "__SL_P_USF", tokenNameLen)) {
323-
memcpy(g_InstallationID, tokenValue, tokenValueLen);
332+
} else if (0 == strcmp(tokenName, "__SL_P_USF")) {
333+
tokenValueLen = MIN(tokenValueLen, sizeof(g_InstallationID)-1);
334+
strncpy(g_InstallationID, tokenValue, tokenValueLen);
324335
g_InstallationID[tokenValueLen] = 0;
325-
} else if (0 == memcmp(tokenName, "__SL_P_USG", tokenNameLen)) {
326-
memcpy(g_SessionToken, tokenValue, tokenValueLen);
336+
} else if (0 == strcmp(tokenName, "__SL_P_USG")) {
337+
tokenValueLen = MIN(tokenValueLen, sizeof(g_SessionToken)-1);
338+
strncpy(g_SessionToken, tokenValue, tokenValueLen);
327339
g_SessionToken[tokenValueLen] = 0;
328-
} else if (0 == memcmp(tokenName, "__SL_P_USH", tokenNameLen)) {
329-
memcpy(g_DeviceName, tokenValue, tokenValueLen);
340+
} else if (0 == strcmp(tokenName, "__SL_P_USH")) {
341+
tokenValueLen = MIN(tokenValueLen, sizeof(g_DeviceName)-1);
342+
strncpy(g_DeviceName, tokenValue, tokenValueLen);
330343
g_DeviceName[tokenValueLen] = 0;
331344
}
332345
}

cc3200/src/cc3200_client_state.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ short loadClientState(ParseClientInternal *parseClient) {
6363
#endif /* CLIENT_DEBUG */
6464

6565
readOffset = readOffset + status;
66-
status = sl_FsRead(clientStateFile, readOffset, (unsigned char *)parseClient->lastPushHash, sizeof(parseClient->lastPushHash));
66+
status = sl_FsRead(clientStateFile, readOffset, (unsigned char *)parseClient->lastPushTime, sizeof(parseClient->lastPushTime));
6767
if (status < 0) {
6868
sl_FsClose(clientStateFile, 0, 0, 0);
6969
return status;
7070
}
7171
#ifdef CLIENT_DEBUG
72-
DEBUG_PRINT("[Parse] Last push hash: %s\r\n", parseClient->lastPushHash);
72+
DEBUG_PRINT("[Parse] Last push time: %s\r\n", parseClient->lastPushTime);
7373
#endif /* CLIENT_DEBUG */
7474

7575
sl_FsClose(clientStateFile, 0, 0, 0);
@@ -145,10 +145,10 @@ short saveClientState(ParseClientInternal *parseClient) {
145145
}
146146

147147
#ifdef CLIENT_DEBUG
148-
DEBUG_PRINT("[Parse] Last push hash: %s\r\n", parseClient->lastPushHash);
148+
DEBUG_PRINT("[Parse] Last push time: %s\r\n", parseClient->lastPushTime);
149149
#endif /* CLIENT_DEBUG */
150150
writeOffset = writeOffset + status;
151-
status = sl_FsWrite(clientStateFile, writeOffset, (unsigned char *)parseClient->lastPushHash, sizeof(parseClient->lastPushHash));
151+
status = sl_FsWrite(clientStateFile, writeOffset, (unsigned char *)parseClient->lastPushTime, sizeof(parseClient->lastPushTime));
152152
if (status < 0) {
153153
#ifdef CLIENT_DEBUG
154154
if (status == SL_FS_ERR_NO_AVAILABLE_BLOCKS) {

cc3200/src/cc3200_utils.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void fetchDeviceOSVersion() {
7373
status = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &configOpt, &configLen, (unsigned char *)(&ver));
7474

7575
if(status >= 0) {
76-
sprintf(g_osVersion, "%lu.%lu.%lu.%lu", ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2], ver.NwpVersion[3]);
76+
snprintf(g_osVersion, sizeof(g_osVersion)-1, "%lu.%lu.%lu.%lu", ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2], ver.NwpVersion[3]);
7777
}
7878
}
7979

@@ -93,11 +93,13 @@ void createNewInstallationId(ParseClientInternal *parseClient) {
9393
randInitialized = TRUE;
9494
}
9595

96-
sprintf(parseClient->installationId, "%x%x%x%x%x%x%x%x-%x%x%x%x-%x%x%x%x-%x%x%x%x-%x%x%x%x%x%x%x%x%x%x%x%x",
97-
rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16,
98-
rand()%16, rand()%16, rand()%16, rand()%16,
99-
rand()%16, rand()%16, rand()%16, rand()%16,
100-
rand()%16, rand()%16, rand()%16, rand()%16,
101-
rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16
102-
);
96+
snprintf(parseClient->installationId,
97+
sizeof(parseClient->installationId)-1,
98+
"%x%x%x%x%x%x%x%x-%x%x%x%x-%x%x%x%x-%x%x%x%x-%x%x%x%x%x%x%x%x%x%x%x%x",
99+
rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16,
100+
rand()%16, rand()%16, rand()%16, rand()%16,
101+
rand()%16, rand()%16, rand()%16, rand()%16,
102+
rand()%16, rand()%16, rand()%16, rand()%16,
103+
rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16, rand()%16
104+
);
103105
}

cc3200/src/installation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void createInstallation(ParseClientInternal *parseClient) {
9999
// Send installation create request and get the object id from the response.
100100
// If the response is a failure, set the instalaltionObjectId back to empty
101101
char content[120];
102-
sprintf(content, "{\"installationId\": \"%s\", \"deviceType\": \"embedded\", \"parseVersion\": \"1.0.0\"}", parseClient->installationId);
102+
snprintf(content, sizeof(content)-1, "{\"installationId\": \"%s\", \"deviceType\": \"embedded\", \"parseVersion\": \"1.0.0\"}", parseClient->installationId);
103103

104104
parseSendRequestInternal((ParseClient)parseClient, "POST", "/1/installations", content, createInstallationCallback, FALSE);
105105
}

cc3200/src/parse_impl.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,34 @@ ParseClient parseInitialize(const char *applicationId, const char *clientKey) {
3636
// Do any one-time intialization of the new client
3737
ParseClientInternal *parseClient = (ParseClientInternal *)malloc(sizeof(ParseClientInternal));
3838

39-
memset(parseClient->applicationId, 0, sizeof(parseClient->applicationId));
40-
memset(parseClient->clientKey, 0, sizeof(parseClient->clientKey));
41-
memset(parseClient->installationObjectId, 0, sizeof(parseClient->installationObjectId));
42-
memset(parseClient->installationId, 0, sizeof(parseClient->installationId));
43-
memset(parseClient->sessionToken, 0, sizeof(parseClient->sessionToken));
39+
if (parseClient != NULL) {
40+
memset(parseClient->applicationId, 0, sizeof(parseClient->applicationId));
41+
memset(parseClient->clientKey, 0, sizeof(parseClient->clientKey));
42+
memset(parseClient->installationObjectId, 0, sizeof(parseClient->installationObjectId));
43+
memset(parseClient->installationId, 0, sizeof(parseClient->installationId));
44+
memset(parseClient->sessionToken, 0, sizeof(parseClient->sessionToken));
4445

45-
// Copy the application id and the client key to the client
46-
strncpy(parseClient->applicationId, applicationId, APPLICATION_ID_MAX_LEN);
47-
strncpy(parseClient->clientKey, clientKey, CLIENT_KEY_MAX_LEN);
46+
// Copy the application id and the client key to the client
47+
strncpy(parseClient->applicationId, applicationId, APPLICATION_ID_MAX_LEN);
48+
strncpy(parseClient->clientKey, clientKey, CLIENT_KEY_MAX_LEN);
4849

4950
#ifdef CLIENT_DEBUG
50-
DEBUG_PRINT("[Parse] Application id: %s.\r\n", parseClient->applicationId);
51-
DEBUG_PRINT("[Parse] Client key: %s.\r\n", parseClient->clientKey);
51+
DEBUG_PRINT("[Parse] Application id: %s.\r\n", parseClient->applicationId);
52+
DEBUG_PRINT("[Parse] Client key: %s.\r\n", parseClient->clientKey);
5253
#endif /* CLIENT_DEBUG */
5354

54-
// initialize the push service data
55-
parseClient->socketHandle = -1;
56-
parseClient->callback = NULL;
57-
parseClient->nFailedPing = 0;
58-
memset(parseClient->lastPushHash, 0, sizeof(parseClient->lastPushHash));
55+
// initialize the push service data
56+
parseClient->socketHandle = -1;
57+
parseClient->callback = NULL;
58+
parseClient->nFailedPing = 0;
59+
memset(parseClient->lastPushTime, 0, sizeof(parseClient->lastPushTime));
5960

60-
loadClientState(parseClient);
61+
loadClientState(parseClient);
62+
#ifdef CLIENT_DEBUG
63+
} else {
64+
DEBUG_PRINT("[Parse] Failed to allocate client handle.\r\n");
65+
#endif /* CLIENT_DEBUG */
66+
}
6167

6268
return (ParseClient)parseClient;
6369
}

cc3200/src/parse_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extern "C"
6868

6969
extern char g_osVersion[OS_VERSION_MAX_LEN+1];
7070

71-
#define PUSH_HASH_MAX_LEN 40
71+
#define PUSH_TIME_MAX_LEN 40
7272

7373
// 10 minutes keep alive
7474
#define PUSH_KEEP_ALIVE 10 * 60 * 1000
@@ -90,7 +90,7 @@ typedef struct _ParseClientInternal {
9090
parsePushCallback callback;
9191
int socketHandle;
9292
int nFailedPing;
93-
char lastPushHash[PUSH_HASH_MAX_LEN + 1];
93+
char lastPushTime[PUSH_TIME_MAX_LEN + 1];
9494
} ParseClientInternal;
9595

9696
/* cc3200_certificate.c */

cc3200/src/push.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ int parseStartPushService(ParseClient client) {
5555
DEBUG_PRINT("[Parse] Push service started.\r\n");
5656
#endif /* CLIENT_DEBUG */
5757

58-
int lastPushHashLen = 0; //strlen(parseClient->lastPushHash);
59-
sprintf(pushDataBuffer,
60-
"{\"installation_id\":\"%s\", \"oauth_key\":\"%s\", \"v\": \"e1.0.0\", \"last\": %s%s%s}\r\n",
61-
parseClient->installationId,
62-
parseClient->applicationId,
63-
lastPushHashLen > 0 ? "\"" : "",
64-
lastPushHashLen > 0 ? parseClient->lastPushHash : "null",
65-
lastPushHashLen > 0 ? "\"" : ""
58+
int lastPushTimeLen = strlen(parseClient->lastPushTime);
59+
snprintf(pushDataBuffer,
60+
sizeof(pushDataBuffer)-1,
61+
"{\"installation_id\":\"%s\", \"oauth_key\":\"%s\", \"v\": \"e1.0.0\", \"last\": %s%s%s}\r\n",
62+
parseClient->installationId,
63+
parseClient->applicationId,
64+
lastPushTimeLen > 0 ? "\"" : "",
65+
lastPushTimeLen > 0 ? parseClient->lastPushTime : "null",
66+
lastPushTimeLen > 0 ? "\"" : ""
6667
);
6768

6869
#ifdef PUSH_DEBUG
@@ -173,19 +174,24 @@ int parseProcessNextPushNotification(ParseClient client) {
173174
if (length > 0 && message != NULL) {
174175
// We assume messages are separated by '\n'.
175176
message[length] = '\0';
176-
if ((strncmp("{}", message, 2) != 0) && (parseClient->callback != NULL)) {
177+
178+
#ifdef PUSH_DEBUG
179+
DEBUG_PRINT("[Parse] Push notification: %s\r\n", message);
180+
#endif /* PUSH_DEBUG */
181+
182+
if (simpleJsonProcessor(message, "time", parseClient->lastPushTime, PUSH_TIME_MAX_LEN)) {
183+
#ifdef PUSH_DEBUG
184+
DEBUG_PRINT("[Parse] Last push time: %s\r\n", parseClient->lastPushTime);
185+
#endif /* PUSH_DEBUG */
186+
saveClientState(parseClient);
187+
}
188+
189+
if (strncmp("{}", message, 2) == 0) {
190+
// we got a heartbeat back
191+
} else if (parseClient->callback != NULL) {
177192
parseClient->callback(client, 0, message);
178-
// int dataLength = -1;
179-
// int dataStart = 0;
180-
// char *messageData = (char *)getPushJson(message+1, strlen(message)-1, &dataStart, &dataLength);
181-
// if (messageData != NULL) {
182-
// simpleJsonProcessor(messageData, "push_hash", parseClient->lastPushHash, PUSH_HASH_MAX_LEN);
183-
//#ifdef PUSH_DEBUG
184-
// DEBUG_PRINT("[Parse] Push hash: %s\r\n", parseClient->lastPushHash);
185-
//#endif /* PUSH_DEBUG */
186-
// saveClientState(parseClient);
187-
// }
188193
}
194+
189195
pushDataBufferUsed -= length + 1;
190196
if (pushDataBufferUsed > 0) {
191197
memmove(pushDataBuffer, pushDataBuffer + length + 1, pushDataBufferUsed);

cc3200/src/request.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int buildRequestHeaders(ParseClientInternal *parseClient, const char *host, cons
4949
int status = 0;
5050

5151
int currentPosition = 0;
52-
int currentSize = sizeof(dataBuffer) - currentPosition;
52+
int currentSize = sizeof(dataBuffer) - currentPosition - 1;
5353

5454
int isGetRequest = strncasecmp(httpVerb, "GET", 3) == 0;
5555
int hasBody = (httpRequestBody != NULL) && (strlen(httpRequestBody) > 0);
@@ -58,6 +58,8 @@ int buildRequestHeaders(ParseClientInternal *parseClient, const char *host, cons
5858
hasBody = FALSE;
5959
}
6060

61+
memset(dataBuffer, 0, sizeof(dataBuffer));
62+
6163
if (isGetRequest != FALSE) {
6264
status = beginHttpGetRequest(dataBuffer + currentPosition, currentSize, host, httpVerb, httpRequestBody);
6365
} else {
@@ -150,7 +152,7 @@ int buildRequestHeaders(ParseClientInternal *parseClient, const char *host, cons
150152
if (status >= 0) {
151153
currentPosition += status;
152154
currentSize -= status;
153-
dataBuffer[currentPosition] = 0;
155+
dataBuffer[currentPosition] = 0;
154156
}
155157

156158
return (status < 0) ? status : currentPosition;

0 commit comments

Comments
 (0)