Skip to content

Commit c2fd38d

Browse files
authored
Merge pull request #2813 from DennisHeimbigner/fixes.dmh
Fix some important bugs in various files
2 parents 0c6fd78 + 58dd530 commit c2fd38d

File tree

12 files changed

+44
-20
lines changed

12 files changed

+44
-20
lines changed

include/ncpathmgr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#ifdef HAVE_DIRENT_H
1515
#include <dirent.h>
1616
#endif
17+
#ifdef HAVE_SYS_TYPES_H
18+
#include <sys/types.h>
19+
#endif
1720
#ifdef HAVE_SYS_STAT_H
1821
#include <sys/stat.h>
1922
#endif

include/ncs3sdk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#ifndef NCS3SDK_H
77
#define NCS3SDK_H 1
88

9+
#define AWSHOST ".amazonaws.com"
10+
#define GOOGLEHOST "storage.googleapis.com"
11+
912
/* Track the server type, if known */
1013
typedef enum NCS3SVC {NCS3UNK=0, /* unknown */
1114
NCS3=1, /* s3.amazon.aws */

libdispatch/dcopy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
694694
int gid;
695695
uintptr_t id;
696696

697-
id = grp;
697+
id = (uintptr_t)grp;
698698
nclistpush(queue,(void*)id); /* prime the queue */
699699
while(nclistlength(queue) > 0) {
700700
id = (uintptr_t)nclistremove(queue,0);
@@ -712,7 +712,7 @@ searchgrouptree(int ncid1, int tid1, int grp, int* tid2)
712712
goto done;
713713
/* push onto the end of the queue */
714714
for(i=0;i<nids;i++) {
715-
id = ids[i];
715+
id = (uintptr_t)ids[i];
716716
nclistpush(queue,(void*)id);
717717
}
718718
free(ids); ids = NULL;

libdispatch/derror.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ const char *nc_strerror(int ncerr1)
267267
case NC_EMPI: return "NetCDF: MPI operation failed.";
268268
case NC_ERCFILE:
269269
return "NetCDF: RC File Failure.";
270-
case NC_ENULLPAD:
270+
case NC_ENULLPAD:
271271
return "NetCDF: File fails strict Null-Byte Header check.";
272-
case NC_EINMEMORY:
272+
case NC_EINMEMORY:
273273
return "NetCDF: In-memory File operation failed.";
274274
case NC_ENCZARR:
275275
return "NetCDF: NCZarr error";

libdispatch/nch5s3comms.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ NCH5_s3comms_s3r_open(const char* root, NCS3SVC svc, const char *region, const c
11521152
/* Compute the signing key */
11531153
if (SUCCEED != NCH5_s3comms_signing_key(&signing_key, access_key, region, iso8601now))
11541154
HGOTO_ERROR(H5E_ARGS, NC_EINVAL, NULL, "problem in NCH5_s3comms_s3comms_signing_key.");
1155-
if (nulllen(signing_key)==0)
1155+
if (signing_key == NULL)
11561156
HGOTO_ERROR(H5E_ARGS, NC_EAUTH, NULL, "signing key cannot be null.");
11571157
handle->signing_key = signing_key;
11581158
signing_key = NULL;
@@ -2033,7 +2033,7 @@ NCH5_s3comms_signing_key(unsigned char **mdp, const char *secret, const char *re
20332033
if ((size_t)ret != (AWS4_secret_len - 1))
20342034
HGOTO_ERRORVA(H5E_ARGS, NC_EINVAL, FAIL, "problem writing AWS4+secret `%s`", secret);
20352035

2036-
if((md = (unsigned char*)malloc(SHA256_DIGEST_LENGTH))==NULL)
2036+
if((md = (unsigned char*)calloc(1,SHA256_DIGEST_LENGTH))==NULL)
20372037
HGOTO_ERROR(H5E_ARGS, NC_ENOMEM, NULL, "could not malloc space for signing key .");
20382038

20392039
/* hash_func, key, len(key), msg, len(msg), digest_dest, digest_len_dest

libdispatch/nclist.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NClist* nclistnew(void)
3131
ncinitialized = 1;
3232
}
3333
*/
34-
l = (NClist*)malloc(sizeof(NClist));
34+
l = (NClist*)calloc(1,sizeof(NClist));
3535
if(l) {
3636
l->alloc=0;
3737
l->length=0;
@@ -286,10 +286,13 @@ nclistclone(const NClist* l, int deep)
286286
void*
287287
nclistextract(NClist* l)
288288
{
289-
void* result = l->content;
289+
void* result = NULL;
290+
if(l) {
291+
result = l->content;
290292
l->alloc = 0;
291293
l->length = 0;
292294
l->content = NULL;
295+
}
293296
return result;
294297
}
295298

libncpoco/cp_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void
4646
ncperr(const char* fcn, NCPSharedLib* lib)
4747
{
4848
const char* msg = dlerror();
49-
lib->err.msg[0] = '\0';
49+
memset(lib->err.msg,0,sizeof(lib->err.msg));
5050
if(msg != NULL) {
5151
strlcat(lib->err.msg,fcn,sizeof(lib->err.msg));
5252
strlcat(lib->err.msg,": ",sizeof(lib->err.msg));

libncpoco/cp_win32.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ load(NCPSharedLib* lib , const char* path0, int flags)
105105
char* msg = NULL;
106106
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
107107
NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &msg, 0, NULL);
108-
if(msg) {
108+
memset(lib->err.msg,0,sizeof(lib->err.msg));
109+
if(msg)
109110
strncpy(lib->err.msg,msg,sizeof(lib->err.msg));
110-
} else
111-
lib->err.msg[0] = '\0';
112111
ret = NC_ENOTFOUND;
113112
goto ldone;
114113
}

libncpoco/ncpoco.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ EXTERNL int
6868
ncpload(NCPSharedLib* lib, const char* path, int flags)
6969
{
7070
if(lib == NULL || path == NULL) return NC_EINVAL;
71+
ncpclearerrmsg(lib);
7172
return lib->api.load(lib,path,flags);
7273
}
7374

7475
EXTERNL int
7576
ncpunload(NCPSharedLib* lib) /* Unloads a shared library. */
7677
{
7778
if(lib == NULL) return NC_EINVAL;
79+
ncpclearerrmsg(lib);
7880
return lib->api.unload(lib);
7981
}
8082

@@ -93,6 +95,7 @@ EXTERNL void*
9395
ncpgetsymbol(NCPSharedLib* lib,const char* name)
9496
{
9597
if(lib == NULL) return NULL;
98+
ncpclearerrmsg(lib);
9699
return lib->api.getsymbol(lib,name);
97100
}
98101

@@ -113,3 +116,11 @@ ncpgeterrmsg(NCPSharedLib* lib)
113116
if(lib == NULL) return NULL;
114117
return (lib->err.msg[0] == '\0' ? NULL : lib->err.msg);
115118
}
119+
120+
/* Clear the last err msg. */
121+
EXTERNL void
122+
ncpclearerrmsg(NCPSharedLib* lib)
123+
{
124+
if(lib == NULL) return;
125+
memset(lib->err.msg,0,sizeof(lib->err.msg));
126+
}

libncpoco/ncpoco.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ EXTERNL const char* ncpgetpath(NCPSharedLib*);
7171
/* Return last err msg */
7272
EXTERNL const char* ncpgeterrmsg(NCPSharedLib* lib);
7373

74+
/* Clear the last err msg. */
75+
EXTERNL void ncpclearerrmsg(NCPSharedLib* lib);
76+
7477
EXTERNL const char* intstr(int err1);
7578

7679
#endif /*NCPOCO_H*/

0 commit comments

Comments
 (0)