@@ -819,11 +819,11 @@ url_readdata(void *ptr, size_t size, size_t nmemb, void *userdata)
819
819
*
820
820
* @param[in] curl CURL struct to modify.
821
821
*/
822
- static void
822
+ static CURLcode
823
823
url_set_protocols (CURL * curl )
824
824
{
825
825
#if CURL_AT_LEAST_VERSION (7 , 85 , 0 )
826
- curl_easy_setopt (curl , CURLOPT_PROTOCOLS_STR , np2srv .url_protocols );
826
+ return curl_easy_setopt (curl , CURLOPT_PROTOCOLS_STR , np2srv .url_protocols );
827
827
#else
828
828
long proto = 0 ;
829
829
char * ptr , * ptr2 ;
@@ -854,7 +854,7 @@ url_set_protocols(CURL *curl)
854
854
ptr = ptr2 + 1 ;
855
855
} while (ptr2 [0 ]);
856
856
857
- curl_easy_setopt (curl , CURLOPT_PROTOCOLS , proto );
857
+ return curl_easy_setopt (curl , CURLOPT_PROTOCOLS , proto );
858
858
#endif
859
859
}
860
860
@@ -871,7 +871,8 @@ url_get(const struct ly_ctx *ly_ctx, const char *url, char **url_data)
871
871
{
872
872
struct nc_server_reply * reply = NULL ;
873
873
CURL * curl ;
874
- char curl_buffer [CURL_ERROR_SIZE ];
874
+ CURLcode res ;
875
+ char curl_buffer [CURL_ERROR_SIZE ] = {0 };
875
876
struct np_url_mem mem_data = {0 };
876
877
877
878
if (!np2srv .url_protocols ) {
@@ -884,14 +885,26 @@ url_get(const struct ly_ctx *ly_ctx, const char *url, char **url_data)
884
885
/* set up libcurl */
885
886
curl_global_init (URL_INIT_FLAGS );
886
887
curl = curl_easy_init ();
887
- url_set_protocols (curl );
888
- curl_easy_setopt (curl , CURLOPT_URL , url );
889
- curl_easy_setopt (curl , CURLOPT_WRITEFUNCTION , url_writedata );
890
- curl_easy_setopt (curl , CURLOPT_WRITEDATA , & mem_data );
891
- curl_easy_setopt (curl , CURLOPT_ERRORBUFFER , curl_buffer );
892
-
893
- /* download data */
894
- if (curl_easy_perform (curl ) != CURLE_OK ) {
888
+ res = url_set_protocols (curl );
889
+ if (res == CURLE_OK ) {
890
+ res = curl_easy_setopt (curl , CURLOPT_URL , url );
891
+ }
892
+ if (res == CURLE_OK ) {
893
+ res = curl_easy_setopt (curl , CURLOPT_WRITEFUNCTION , url_writedata );
894
+ }
895
+ if (res == CURLE_OK ) {
896
+ res = curl_easy_setopt (curl , CURLOPT_WRITEDATA , & mem_data );
897
+ }
898
+ if (res == CURLE_OK ) {
899
+ res = curl_easy_setopt (curl , CURLOPT_ERRORBUFFER , curl_buffer );
900
+ }
901
+
902
+ if (res == CURLE_OK ) {
903
+ /* download data */
904
+ res = curl_easy_perform (curl );
905
+ }
906
+
907
+ if (res != CURLE_OK ) {
895
908
ERR ("Failed to download data (curl: %s)." , curl_buffer );
896
909
reply = np_reply_err_op_failed (NULL , ly_ctx , curl_buffer );
897
910
goto cleanup ;
@@ -968,7 +981,7 @@ np_op_export_url(const struct ly_ctx *ly_ctx, const char *url, struct lyd_node *
968
981
CURL * curl ;
969
982
struct np_url_mem mem_data ;
970
983
CURLcode r = 0 ;
971
- char curl_buffer [CURL_ERROR_SIZE ], * str_data = NULL ;
984
+ char curl_buffer [CURL_ERROR_SIZE ] = { 0 } , * str_data = NULL ;
972
985
struct lyd_node * config ;
973
986
974
987
if (!np2srv .url_protocols ) {
@@ -998,7 +1011,7 @@ np_op_export_url(const struct ly_ctx *ly_ctx, const char *url, struct lyd_node *
998
1011
/* set up libcurl */
999
1012
curl_global_init (URL_INIT_FLAGS );
1000
1013
curl = curl_easy_init ();
1001
- url_set_protocols (curl );
1014
+ r = url_set_protocols (curl );
1002
1015
if (!r ) {
1003
1016
r = curl_easy_setopt (curl , CURLOPT_URL , url );
1004
1017
}
0 commit comments