Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of azure_c_shared_utility by
Revision 26:b38c66e3e45e, committed 2017-05-08
- Comitter:
- AzureIoTClient
- Date:
- Mon May 08 10:51:21 2017 -0700
- Parent:
- 25:8507bf644fdf
- Child:
- 27:8656a313842b
- Commit message:
- 1.1.14
Changed in this revision
| sastoken.c | Show annotated file Show diff for this revision Revisions of this file |
--- a/sastoken.c Fri Apr 21 14:51:10 2017 -0700
+++ b/sastoken.c Mon May 08 10:51:21 2017 -0700
@@ -2,6 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
#include "azure_c_shared_utility/gballoc.h"
#include "azure_c_shared_utility/sastoken.h"
#include "azure_c_shared_utility/urlencode.h"
@@ -38,8 +40,8 @@
/*Codes_SRS_SASTOKEN_25_025: [**SASToken_Validate shall get the SASToken value by invoking STRING_c_str on the handle.**]***/
const char* sasTokenArray = STRING_c_str(sasToken);
- /***Codes_SRS_SASTOKEN_25_024: [**If handle is NULL then SASToken_Validate shall return false.**] ***/
- /*Codes_SRS_SASTOKEN_25_026: [**If STRING_c_str on handle return NULL then SASToken_Validate shall return false.**]***/
+ /* Codes_SRS_SASTOKEN_25_024: [**If handle is NULL then SASToken_Validate shall return false.**] */
+ /* Codes_SRS_SASTOKEN_25_026: [**If STRING_c_str on handle return NULL then SASToken_Validate shall return false.**] */
if (sasToken == NULL || sasTokenArray == NULL)
{
result = false;
@@ -49,8 +51,8 @@
int seStart = -1, seStop = -1;
int srStart = -1, srStop = -1;
int sigStart = -1, sigStop = -1;
- int tokenLength = (int) STRING_length(sasToken);
- int i ;
+ int tokenLength = (int)STRING_length(sasToken);
+ int i;
for (i = 0; i < tokenLength; i++)
{
if (sasTokenArray[i] == 's' && sasTokenArray[i + 1] == 'e' && sasTokenArray[i + 2] == '=') // Look for se=
@@ -74,9 +76,8 @@
else
seStart = -1;
}
- continue;
}
- if (sasTokenArray[i] == 's' && sasTokenArray[i + 1] == 'r' && sasTokenArray[i + 2] == '=') // Look for sr=
+ else if (sasTokenArray[i] == 's' && sasTokenArray[i + 1] == 'r' && sasTokenArray[i + 2] == '=') // Look for sr=
{
srStart = i + 3;
if (seStart > 0 && seStop < 0)
@@ -97,9 +98,8 @@
else
srStart = -1;
}
- continue;
}
- if (sasTokenArray[i] == 's' && sasTokenArray[i + 1] == 'i' && sasTokenArray[i + 2] == 'g' && sasTokenArray[i + 3] == '=') // Look for sig=
+ else if (sasTokenArray[i] == 's' && sasTokenArray[i + 1] == 'i' && sasTokenArray[i + 2] == 'g' && sasTokenArray[i + 3] == '=') // Look for sig=
{
sigStart = i + 4;
if (srStart > 0 && srStop < 0)
@@ -120,9 +120,9 @@
else
sigStart = -1;
}
- continue;
}
}
+
/*Codes_SRS_SASTOKEN_25_027: [**If SASTOKEN does not obey the SASToken format then SASToken_Validate shall return false.**]***/
/*Codes_SRS_SASTOKEN_25_028: [**SASToken_validate shall check for the presence of sr, se and sig from the token and return false if not found**]***/
if (seStart < 0 || srStart < 0 || sigStart < 0)
@@ -161,12 +161,18 @@
else
{
double expiry;
+ // Add the Null terminator here
+ memset(expiryASCII, 0, seStop - seStart + 1);
for (i = seStart; i < seStop; i++)
{
+ // The se contains the expiration values, if a & token is encountered then
+ // the se field is complete.
+ if (sasTokenArray[i] == '&')
+ {
+ break;
+ }
expiryASCII[i - seStart] = sasTokenArray[i];
}
- expiryASCII[seStop - seStart] = '\0';
-
expiry = getExpiryValue(expiryASCII);
/*Codes_SRS_SASTOKEN_25_029: [**SASToken_validate shall check for expiry time from token and if token has expired then would return false **]***/
if (expiry <= 0)
