#include "lib.h"
#include "buffer.h"
#include "unichar.h"
+#include "safe-memset.h"
#include "istream.h"
#include "istream-failure-at.h"
#include "istream-sized.h"
char *error;
bool auth_response:1;
+ bool auth_response_buffered:1;
};
static inline void ATTR_FORMAT(3, 4)
return parser;
}
+void smtp_command_parser_clear(struct smtp_command_parser *parser)
+{
+ if (parser->auth_response_buffered) {
+ if (parser->line_buffer != NULL)
+ buffer_clear_safe(parser->line_buffer);
+ if (parser->state.cmd_params != NULL) {
+ safe_memset(parser->state.cmd_params, 0,
+ strlen(parser->state.cmd_params));
+ }
+ }
+ parser->auth_response_buffered = FALSE;
+}
+
void smtp_command_parser_deinit(struct smtp_command_parser **_parser)
{
struct smtp_command_parser *parser = *_parser;
+ smtp_command_parser_clear(parser);
+
i_stream_unref(&parser->data);
buffer_free(&parser->line_buffer);
i_free(parser->state.cmd_name);
static void smtp_command_parser_restart(struct smtp_command_parser *parser)
{
+ smtp_command_parser_clear(parser);
+
buffer_free(&parser->line_buffer);
i_free(parser->state.cmd_name);
i_free(parser->state.cmd_params);
parser->line_buffer = buffer_create_dynamic(
default_pool, buf_size);
}
+ if (parser->auth_response)
+ parser->auth_response_buffered = TRUE;
buffer_append(parser->line_buffer, parser->cur,
(p - parser->cur));
return -1;
}
+ if (parser->auth_response)
+ parser->auth_response_buffered = TRUE;
if (parser->line_buffer == NULL) {
/* Buffered only in input stream */
parser->state.cmd_params = i_strdup_until(parser->cur, mp);
const struct smtp_command_limits *limits) ATTR_NULL(2);
void smtp_command_parser_deinit(struct smtp_command_parser **_parser);
+/* Clear any sensitive data in the parser. Any returned auth response line will
+ be cleared now. Call this as soon as the returned auth response is not
+ needed anymore. It will be cleared eventually when the parser continues with
+ the next command/auth response and when it is deinitialized, but that is not
+ optimal. */
+void smtp_command_parser_clear(struct smtp_command_parser *parser);
+
void smtp_command_parser_set_stream(struct smtp_command_parser *parser,
struct istream *input);