Skip to content

Commit fc796b3

Browse files
Fix handling of CURLOPT_CAINFO and CURLOPT_CAPATH
re: Issue Unidata/netcdf4-python#1246 This provides a **partial** solution to the above PR. The underlying problem is with libcurl, but at least a workaround should be possible by creating a "~/.ncrc" file containing the line "HTTP.SSL_CAINFO=\<path to the cert (.crt) file\>". This was not working for obscure reasons. This PR should fix it. ## Misc. Other Changes * Update/fix configure.ac to properly test for libcurl version >= 7.66.0 * Update include/netcdf_json.h * Remove use of strlcat from plugins. * Fix applicability of .rc file entries
1 parent 2bed69a commit fc796b3

File tree

8 files changed

+41
-33
lines changed

8 files changed

+41
-33
lines changed

configure.ac

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,19 @@ AC_MSG_RESULT([${havecurloption}])
530530
if test $havecurloption = yes; then
531531
AC_DEFINE([HAVE_CURLOPT_KEEPALIVE],[1],[Is CURLOPT_TCP_KEEPALIVE defined])
532532
fi
533+
533534
# CURLOPT_VERIFYHOST semantics differ depending on version
534535
AC_MSG_CHECKING([whether libcurl is version 7.66 or later?])
535536
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
536537
[#include "curl/curl.h"],
537538
[[
538-
#if LIBCURL_VERSION_NUM < 0x074200
539+
#if !CURL_AT_LEAST_VERSION(7,66,0)
539540
error "<7.66";
540541
#endif
541542
]])], [libcurl766=yes], [libcurl766=no])
542-
543543
AC_MSG_RESULT([$libcurl766])
544-
if test x$libcurl66 = xno; then
545-
AC_DEFINE([HAVE_LIBCURL_766],[1],[Is libcurl version 7.66 or later])
544+
if test x$libcurl766 = xyes; then
545+
AC_DEFINE([HAVE_LIBCURL_766],[1],[libcurl version is 7.66 or later])
546546
fi
547547

548548
CFLAGS="$SAVECFLAGS"

include/netcdf_json.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,13 @@ testdouble(const char* word)
613613
double d;
614614
int count = 0;
615615
/* Check for Nan and Infinity */
616-
if(strcasecmp("nan",word)==0) return NCJTHROW(NCJ_OK);
617-
if(strcasecmp("infinity",word)==0) return NCJTHROW(NCJ_OK);
618-
if(strcasecmp("-infinity",word)==0) return NCJTHROW(NCJ_OK);
616+
if(0==(int)strcasecmp("nan",word)) return NCJTHROW(NCJ_OK);
617+
if(0==(int)strcasecmp("infinity",word)) return NCJTHROW(NCJ_OK);
618+
if(0==(int)strcasecmp("-infinity",word)) return NCJTHROW(NCJ_OK);
619619
/* Allow the XXXf versions as well */
620-
if(strcasecmp("nanf",word)==0) return NCJTHROW(NCJ_OK);
621-
if(strcasecmp("infinityf",word)==0) return NCJTHROW(NCJ_OK);
622-
if(strcasecmp("-infinityf",word)==0) return NCJTHROW(NCJ_OK);
620+
if(0==(int)strcasecmp("nanf",word)) return NCJTHROW(NCJ_OK);
621+
if(0==(int)strcasecmp("infinityf",word)) return NCJTHROW(NCJ_OK);
622+
if(0==(int)strcasecmp("-infinityf",word)) return NCJTHROW(NCJ_OK);
623623
/* Try to convert to number */
624624
ncvt = sscanf(word,"%lg%n",&d,&count);
625625
return NCJTHROW((ncvt == 1 && strlen(word)==count ? NCJ_OK : NCJ_ERR));
@@ -1226,8 +1226,7 @@ NCJtotext(const NCjson* json)
12261226
char* text = NULL;
12271227
if(json == NULL) {strcpy(outtext,"<null>"); goto done;}
12281228
(void)NCJunparse(json,0,&text);
1229-
outtext[0] = '\0';
1230-
strlcat(outtext,text,sizeof(outtext));
1229+
strncpy(outtext,text,sizeof(outtext));
12311230
nullfree(text);
12321231
done:
12331232
return outtext;

libdispatch/drc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,12 @@ rcequal(NCRCentry* e1, NCRCentry* e2)
567567
nulltest = 0;
568568
if(e1->host == NULL) nulltest |= 1;
569569
if(e2->host == NULL) nulltest |= 2;
570+
/* Use host to decide if entry applies */
570571
switch (nulltest) {
571572
case 0: if(strcmp(e1->host,e2->host) != 0) {return 0;} break;
572-
case 1: return 0;
573-
case 2: return 0;
574-
case 3: break;
573+
case 1: break; /* .rc->host == NULL && candidate->host != NULL */
574+
case 2: return 0; /* .rc->host != NULL && candidate->host == NULL */
575+
case 3: break; /* .rc->host == NULL && candidate->host == NULL */
575576
default: return 0;
576577
}
577578
/* test urlpath take NULL into account*/
@@ -580,9 +581,9 @@ rcequal(NCRCentry* e1, NCRCentry* e2)
580581
if(e2->urlpath == NULL) nulltest |= 2;
581582
switch (nulltest) {
582583
case 0: if(strcmp(e1->urlpath,e2->urlpath) != 0) {return 0;} break;
583-
case 1: return 0;
584-
case 2: return 0;
585-
case 3: break;
584+
case 1: break; /* .rc->urlpath == NULL && candidate->urlpath != NULL */
585+
case 2: return 0; /* .rc->urlpath != NULL && candidate->urlpath == NULL */
586+
case 3: break; /* .rc->urlpath == NULL && candidate->urlpath == NULL */
586587
default: return 0;
587588
}
588589
return 1;

libdispatch/ncjson.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,7 @@ NCJtotext(const NCjson* json)
10801080
char* text = NULL;
10811081
if(json == NULL) {strcpy(outtext,"<null>"); goto done;}
10821082
(void)NCJunparse(json,0,&text);
1083-
outtext[0] = '\0';
1084-
strlcat(outtext,text,sizeof(outtext));
1083+
strncpy(outtext,text,sizeof(outtext));
10851084
nullfree(text);
10861085
done:
10871086
return outtext;

oc2/occurlfunctions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ ocset_curlflag(OCstate* state, int flag)
130130
case CURLOPT_USE_SSL:
131131
case CURLOPT_SSLCERT: case CURLOPT_SSLKEY:
132132
case CURLOPT_SSL_VERIFYPEER: case CURLOPT_SSL_VERIFYHOST:
133+
case CURLOPT_CAINFO: case CURLOPT_CAPATH:
133134
{
134135
struct ssl* ssl = &state->auth->ssl;
135136
/* VERIFYPEER == 0 => VERIFYHOST == 0 */

plugins/H5Znoop.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,21 @@ NCZ_noop_hdf5_to_codec(size_t nparams, const unsigned* params, char** codecp)
230230
int i,stat = NC_NOERR;
231231
char json[8192];
232232
char value[1024];
233+
size_t jlen, count;
233234

234235
if(nparams != 0 && params == NULL)
235236
{stat = NC_EINVAL; goto done;}
236237

237-
snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_noop_codec.codecid);
238+
239+
jlen = sizeof(json);
240+
count = snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_noop_codec.codecid);
238241
for(i=0;i<nparams;i++) {
239-
snprintf(value,sizeof(value),", \"p%d\": \"%u\"",i,params[i]);
240-
strlcat(json,value,sizeof(json));
242+
size_t len = snprintf(value,sizeof(value),", \"p%d\": \"%u\"",i,params[i]);
243+
count += len; assert(jlen > count);
244+
strcat(json,value);
241245
}
242-
strlcat(json,"}",sizeof(json));
246+
count += 1; assert(jlen > count);
247+
strcat(json,"}");
243248
if(codecp) {
244249
if((*codecp = strdup(json))==NULL) {stat = NC_ENOMEM; goto done;}
245250
}

plugins/Makefile.am

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ AM_LDFLAGS += $(plugin_version_info)
2121
endif !ISCYGWIN
2222
endif !ISMINGW
2323

24-
# Create an alternate directory if not installing or for noinst installs.
24+
# Create an alternate directory if not installing.
2525
ALTPLUGINDIR = ${abs_top_builddir}/plugins/plugindir
2626

2727
RPATH = -rpath $(abs_builddir)/.libs
@@ -80,11 +80,11 @@ endif # ENABLE_NCZARR_FILTERS
8080

8181
if ENABLE_PLUGINS
8282

83-
# The NCZarr codec libraries
83+
# The NCZarr codec libraries (they need libnetcdf)
8484
lib__nczstdfilters_la_SOURCES = NCZstdfilters.c
85-
lib__nczstdfilters_la_LIBADD = $(LIBADD)
85+
lib__nczstdfilters_la_LIBADD = $(LIBADD) $(top_builddir)/liblib/libnetcdf.la
8686
lib__nczhdf5filters_la_SOURCES = NCZhdf5filters.c
87-
lib__nczhdf5filters_la_LIBADD = $(LIBADD)
87+
lib__nczhdf5filters_la_LIBADD = $(LIBADD) $(top_builddir)/liblib/libnetcdf.la
8888

8989
plugins_to_install += lib__nczhdf5filters.la
9090
plugins_to_install += lib__nczstdfilters.la
@@ -119,7 +119,6 @@ lib__nch5unknown_la_SOURCES = H5Zunknown.c
119119
lib__nch5unknown_la_LDFLAGS = $(AM_LDFLAGS) ${RPATH}
120120

121121
check_LTLIBRARIES += lib__nch5noop.la lib__nch5noop1.la lib__nch5unknown.la
122-
# findplugin.sh needs these plugins, and I want to see if these get built properly
123122
check_LTLIBRARIES += lib__nch5misc.la lib__nczmisc.la
124123

125124
# Bzip2 is used to test more complex filters

plugins/NCZmisc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ NCZ_misc_hdf5_to_codec(size_t nparams, const unsigned* params, char** codecp)
156156
int i,stat = NC_NOERR;
157157
char json[4096];
158158
char value[1024];
159+
size_t count, jlen;
159160

160161
if(nparams == 0 || params == NULL)
161162
{stat = NC_EINVAL; goto done;}
@@ -164,12 +165,15 @@ NCZ_misc_hdf5_to_codec(size_t nparams, const unsigned* params, char** codecp)
164165
stat = NC_EINVAL;
165166
goto done;
166167
}
167-
snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_misc_codec.codecid);
168+
jlen = sizeof(json);
169+
count = snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_misc_codec.codecid);
168170
for(i=0;i<14;i++) {
169-
snprintf(value,sizeof(value),", \"%s\": \"%u\"",fields[i],params[i]);
170-
strlcat(json,value,sizeof(json));
171+
size_t len = snprintf(value,sizeof(value),", \"%s\": \"%u\"",fields[i],params[i]);
172+
count += len; assert(jlen > count);
173+
strcat(json,value);
171174
}
172-
strlcat(json,"}",sizeof(json));
175+
count += 1; assert(jlen > count);
176+
strcat(json,"}");
173177
if(codecp) {
174178
if((*codecp = strdup(json))==NULL) {stat = NC_ENOMEM; goto done;}
175179
}

0 commit comments

Comments
 (0)