diff options
Diffstat (limited to 'tools/h5import')
-rwxr-xr-x | tools/h5import/h5import.c | 25 | ||||
-rwxr-xr-x | tools/h5import/h5import.h | 3 |
2 files changed, 22 insertions, 6 deletions
diff --git a/tools/h5import/h5import.c b/tools/h5import/h5import.c index 3818829..60ef494 100755 --- a/tools/h5import/h5import.c +++ b/tools/h5import/h5import.c @@ -1587,16 +1587,29 @@ static int parsePathInfo(struct path_info *path, char *temp) { const char delimiter[] = "/"; - char *token = (char*) malloc(255*sizeof(char)); + char *token; int i=0; + const char *err1 = "Path string larger than MAX_PATH_NAME_LENGTH.\n"; + + token = HDstrtok (temp, delimiter); + if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH) + { + (void) fprintf(stderr, err1); + return (-1); + } + HDstrcpy(path->group[i++],token); - HDstrcpy(path->group[i++],HDstrtok (temp, delimiter)); while (1) { token = HDstrtok (NULL, delimiter); if (token == NULL) break; + if (HDstrlen(token) >= MAX_PATH_NAME_LENGTH) + { + (void) fprintf(stderr, err1); + return (-1); + } HDstrcpy(path->group[i++],token); } path->count = i; @@ -1608,11 +1621,12 @@ parseDimensions(struct Input *in, char *strm) { const char delimiter[] = ","; char temp[255]; - char *token = (char*) malloc(255*sizeof(char)); + char *token; int i=0; const char *err1 = "Unable to allocate dynamic memory.\n"; - HDstrcpy(temp, strm); + HDstrncpy(temp, strm, sizeof(temp)); + temp[sizeof(temp)-1] = '\0'; HDstrtok (temp, delimiter); while (1) @@ -1631,7 +1645,8 @@ parseDimensions(struct Input *in, char *strm) } i=0; - HDstrcpy(temp, strm); + HDstrncpy(temp, strm, sizeof(temp)); + temp[sizeof(temp)-1] = '\0'; in->sizeOfDimension[i++] = HDstrtol(HDstrtok (temp, delimiter), NULL, BASE_10); while (1) diff --git a/tools/h5import/h5import.h b/tools/h5import/h5import.h index c43b0cf..cbc6bf2 100755 --- a/tools/h5import/h5import.h +++ b/tools/h5import/h5import.h @@ -38,6 +38,7 @@ #define ERR 20 /* invalid token */ #define MAX_GROUPS_IN_PATH 20 +#define MAX_PATH_NAME_LENGTH 255 #define NUM_KEYS 14 #define MIN_NUM_DIMENSION 1 #define MAX_NUM_DIMENSION 32 @@ -73,7 +74,7 @@ struct path_info { - char group[MAX_GROUPS_IN_PATH][255]; + char group[MAX_GROUPS_IN_PATH][MAX_PATH_NAME_LENGTH]; int count; }; |