diff options
author | Werner Koch <[email protected]> | 2018-11-26 19:22:24 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2018-11-26 19:22:24 +0000 |
commit | bd8668c120ac0f725edb092b2c4ca49ffdb78ed2 (patch) | |
tree | ffeea782e9dc6435822f3b3f1c950c7222ff93b9 /src/estream.c | |
parent | core: Add a limited version of gpgrt_ftruncate. (diff) | |
download | libgpg-error-bd8668c120ac0f725edb092b2c4ca49ffdb78ed2.tar.gz libgpg-error-bd8668c120ac0f725edb092b2c4ca49ffdb78ed2.zip |
core: New functions gpgrt_fprintf_sf anf gpgrt_fprintf_sf_unlocked.
* src/gpg-error.h.in (gpgrt_string_filter_t): New type.
(gpgrt_fprintf_sf, gpgrt_fprintf_sf_unlocked): New.
* src/gpg-error.vers, src/gpg-error.def.in: Add them.
* src/visibility.c (gpgrt_fprintf_sf): New.
(gpgrt_fprintf_sf_unlocked): New.
* src/estream-printf.c (pr_string): Add and use args sf, sfvalue and
string_no.
(do_format): Add args sf and sfvalue. Keep a string format counter.
(_gpgrt_estream_format): Add args sf and sfvalue. Change all callers
to provide NULL for them.
* src/estream.c (_gpgrt_vfprintf_unlocked, _gpgrt_vfprintf): Add sf
and sfvalue and adjust all callers.
(do_print_stream): Ditto.
* tests/t-printf.c (stream_to_string): New.
(struct sfstate_s): New.
(string_filter): New.
(check_fprintf_sf): New.
(main): Call new test.
--
The actual reason to implement these functions is to enhance the
internal logging function with a filter to sanitized strings so that
control values or other things can be quoted.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/estream.c')
-rw-r--r-- | src/estream.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/estream.c b/src/estream.c index 72e93e0..3645dfe 100644 --- a/src/estream.c +++ b/src/estream.c @@ -2982,12 +2982,13 @@ print_writer (void *outfncarg, const char *buf, size_t buflen) /* The core of our printf function. This is called in locked state. */ static int do_print_stream (estream_t _GPGRT__RESTRICT stream, + gpgrt_string_filter_t sf, void *sfvalue, const char *_GPGRT__RESTRICT format, va_list ap) { int rc; stream->intern->print_ntotal = 0; - rc = _gpgrt_estream_format (print_writer, stream, format, ap); + rc = _gpgrt_estream_format (print_writer, stream, sf, sfvalue, format, ap); if (rc) return -1; return (int)stream->intern->print_ntotal; @@ -4444,22 +4445,24 @@ _gpgrt_read_line (estream_t stream, int _gpgrt_vfprintf_unlocked (estream_t _GPGRT__RESTRICT stream, + gpgrt_string_filter_t sf, void *sfvalue, const char *_GPGRT__RESTRICT format, va_list ap) { - return do_print_stream (stream, format, ap); + return do_print_stream (stream, sf, sfvalue, format, ap); } int _gpgrt_vfprintf (estream_t _GPGRT__RESTRICT stream, + gpgrt_string_filter_t sf, void *sfvalue, const char *_GPGRT__RESTRICT format, va_list ap) { int ret; lock_stream (stream); - ret = do_print_stream (stream, format, ap); + ret = do_print_stream (stream, sf, sfvalue, format, ap); unlock_stream (stream); return ret; @@ -4474,7 +4477,7 @@ _gpgrt_fprintf_unlocked (estream_t _GPGRT__RESTRICT stream, va_list ap; va_start (ap, format); - ret = do_print_stream (stream, format, ap); + ret = do_print_stream (stream, NULL, NULL, format, ap); va_end (ap); return ret; @@ -4490,7 +4493,7 @@ _gpgrt_fprintf (estream_t _GPGRT__RESTRICT stream, va_list ap; va_start (ap, format); lock_stream (stream); - ret = do_print_stream (stream, format, ap); + ret = do_print_stream (stream, NULL, NULL, format, ap); unlock_stream (stream); va_end (ap); |