mirror of
https://github.com/curl/curl.git
synced 2025-09-10 06:02:42 +03:00
tool_ssls: switch to tool-specific get_line function
Instead of picky-backing on the libcurl one using the curlx shortcut, which is fragile since the libcurl one is not present in all builds. Reported-by: mschroeder-fzj on github Fixes #16201 Closes #16203
This commit is contained in:
parent
3814fb5a9f
commit
d8618f4d84
|
@ -32,14 +32,12 @@
|
||||||
# libcurl sources to include in curltool lib we use for test binaries
|
# libcurl sources to include in curltool lib we use for test binaries
|
||||||
CURLTOOL_LIBCURL_CFILES = \
|
CURLTOOL_LIBCURL_CFILES = \
|
||||||
../lib/base64.c \
|
../lib/base64.c \
|
||||||
../lib/dynbuf.c \
|
../lib/dynbuf.c
|
||||||
../lib/curl_get_line.c
|
|
||||||
|
|
||||||
# libcurl has sources that provide functions named curlx_* that are not part of
|
# libcurl has sources that provide functions named curlx_* that are not part of
|
||||||
# the official API, but we reuse the code here to avoid duplication.
|
# the official API, but we reuse the code here to avoid duplication.
|
||||||
CURLX_CFILES = \
|
CURLX_CFILES = \
|
||||||
../lib/base64.c \
|
../lib/base64.c \
|
||||||
../lib/curl_get_line.c \
|
|
||||||
../lib/curl_multibyte.c \
|
../lib/curl_multibyte.c \
|
||||||
../lib/dynbuf.c \
|
../lib/dynbuf.c \
|
||||||
../lib/nonblock.c \
|
../lib/nonblock.c \
|
||||||
|
@ -50,7 +48,6 @@ CURLX_CFILES = \
|
||||||
|
|
||||||
CURLX_HFILES = \
|
CURLX_HFILES = \
|
||||||
../lib/curl_ctype.h \
|
../lib/curl_ctype.h \
|
||||||
../lib/curl_get_line.h \
|
|
||||||
../lib/curl_multibyte.h \
|
../lib/curl_multibyte.h \
|
||||||
../lib/curl_setup.h \
|
../lib/curl_setup.h \
|
||||||
../lib/dynbuf.h \
|
../lib/dynbuf.h \
|
||||||
|
|
|
@ -43,8 +43,6 @@
|
||||||
static const char *unslashquote(const char *line, char *param);
|
static const char *unslashquote(const char *line, char *param);
|
||||||
|
|
||||||
#define MAX_CONFIG_LINE_LENGTH (10*1024*1024)
|
#define MAX_CONFIG_LINE_LENGTH (10*1024*1024)
|
||||||
static bool my_get_line(FILE *fp, struct curlx_dynbuf *, bool *error);
|
|
||||||
|
|
||||||
|
|
||||||
/* return 0 on everything-is-fine, and non-zero otherwise */
|
/* return 0 on everything-is-fine, and non-zero otherwise */
|
||||||
int parseconfig(const char *filename, struct GlobalConfig *global)
|
int parseconfig(const char *filename, struct GlobalConfig *global)
|
||||||
|
@ -241,8 +239,6 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
|
||||||
|
|
||||||
if(alloced_param)
|
if(alloced_param)
|
||||||
Curl_safefree(param);
|
Curl_safefree(param);
|
||||||
|
|
||||||
curlx_dyn_reset(&buf);
|
|
||||||
}
|
}
|
||||||
curlx_dyn_free(&buf);
|
curlx_dyn_free(&buf);
|
||||||
if(file != stdin)
|
if(file != stdin)
|
||||||
|
@ -301,22 +297,45 @@ static const char *unslashquote(const char *line, char *param)
|
||||||
/*
|
/*
|
||||||
* Reads a line from the given file, ensuring is NUL terminated.
|
* Reads a line from the given file, ensuring is NUL terminated.
|
||||||
*/
|
*/
|
||||||
static bool my_get_line(FILE *fp, struct curlx_dynbuf *db,
|
|
||||||
bool *error)
|
|
||||||
{
|
|
||||||
char buf[4096];
|
|
||||||
*error = FALSE;
|
|
||||||
do {
|
|
||||||
/* fgets() returns s on success, and NULL on error or when end of file
|
|
||||||
occurs while no characters have been read. */
|
|
||||||
if(!fgets(buf, sizeof(buf), fp))
|
|
||||||
/* only if there is data in the line, return TRUE */
|
|
||||||
return curlx_dyn_len(db);
|
|
||||||
if(curlx_dyn_add(db, buf)) {
|
|
||||||
*error = TRUE; /* error */
|
|
||||||
return FALSE; /* stop reading */
|
|
||||||
}
|
|
||||||
} while(!strchr(buf, '\n'));
|
|
||||||
|
|
||||||
return TRUE; /* continue */
|
bool my_get_line(FILE *input, struct dynbuf *buf, bool *error)
|
||||||
|
{
|
||||||
|
CURLcode result;
|
||||||
|
char buffer[128];
|
||||||
|
curlx_dyn_reset(buf);
|
||||||
|
while(1) {
|
||||||
|
char *b = fgets(buffer, sizeof(buffer), input);
|
||||||
|
|
||||||
|
if(b) {
|
||||||
|
size_t rlen = strlen(b);
|
||||||
|
|
||||||
|
if(!rlen)
|
||||||
|
break;
|
||||||
|
|
||||||
|
result = curlx_dyn_addn(buf, b, rlen);
|
||||||
|
if(result) {
|
||||||
|
/* too long line or out of memory */
|
||||||
|
*error = TRUE;
|
||||||
|
return FALSE; /* error */
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(b[rlen-1] == '\n')
|
||||||
|
/* end of the line */
|
||||||
|
return TRUE; /* all good */
|
||||||
|
|
||||||
|
else if(feof(input)) {
|
||||||
|
/* append a newline */
|
||||||
|
result = curlx_dyn_addn(buf, "\n", 1);
|
||||||
|
if(result) {
|
||||||
|
/* too long line or out of memory */
|
||||||
|
*error = TRUE;
|
||||||
|
return FALSE; /* error */
|
||||||
|
}
|
||||||
|
return TRUE; /* all good */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,6 @@
|
||||||
|
|
||||||
int parseconfig(const char *filename, struct GlobalConfig *config);
|
int parseconfig(const char *filename, struct GlobalConfig *config);
|
||||||
|
|
||||||
|
bool my_get_line(FILE *fp, struct curlx_dynbuf *db, bool *error);
|
||||||
|
|
||||||
#endif /* HEADER_CURL_TOOL_PARSECFG_H */
|
#endif /* HEADER_CURL_TOOL_PARSECFG_H */
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include "tool_ssls.h"
|
#include "tool_ssls.h"
|
||||||
#include "dynbuf.h"
|
#include "dynbuf.h"
|
||||||
#include "curl_base64.h"
|
#include "curl_base64.h"
|
||||||
#include "curl_get_line.h"
|
#include "tool_parsecfg.h"
|
||||||
|
|
||||||
/* The maximum line length for an ecoded session ticket */
|
/* The maximum line length for an ecoded session ticket */
|
||||||
#define MAX_SSLS_LINE (64 * 1024)
|
#define MAX_SSLS_LINE (64 * 1024)
|
||||||
|
@ -68,6 +68,7 @@ CURLcode tool_ssls_load(struct GlobalConfig *global,
|
||||||
size_t shmac_len, sdata_len;
|
size_t shmac_len, sdata_len;
|
||||||
CURLcode r = CURLE_OK;
|
CURLcode r = CURLE_OK;
|
||||||
int i, imported;
|
int i, imported;
|
||||||
|
bool error = FALSE;
|
||||||
|
|
||||||
curlx_dyn_init(&buf, MAX_SSLS_LINE);
|
curlx_dyn_init(&buf, MAX_SSLS_LINE);
|
||||||
fp = fopen(filename, FOPEN_READTEXT);
|
fp = fopen(filename, FOPEN_READTEXT);
|
||||||
|
@ -81,7 +82,7 @@ CURLcode tool_ssls_load(struct GlobalConfig *global,
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
i = imported = 0;
|
i = imported = 0;
|
||||||
while(Curl_get_line(&buf, fp)) {
|
while(my_get_line(fp, &buf, &error)) {
|
||||||
++i;
|
++i;
|
||||||
curl_free(shmac);
|
curl_free(shmac);
|
||||||
curl_free(sdata);
|
curl_free(sdata);
|
||||||
|
@ -123,6 +124,9 @@ CURLcode tool_ssls_load(struct GlobalConfig *global,
|
||||||
}
|
}
|
||||||
++imported;
|
++imported;
|
||||||
}
|
}
|
||||||
|
if(error)
|
||||||
|
r = CURLE_FAILED_INIT;
|
||||||
|
else
|
||||||
r = CURLE_OK;
|
r = CURLE_OK;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user