mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-29 21:33:02 +00:00
ssl_mail_client: Check return value of mbedtls_snprintf
The return value of snprintf() is the number of characters (excluding the null terminator) which would have been written to the buffer if enough space had been available. Thus, a return value of size or more means the output was truncated. Signed-off-by: Mingjie Shen <shen497@purdue.edu>
This commit is contained in:
parent
0fc20cd447
commit
8e35d96057
@ -728,6 +728,10 @@ usage:
|
||||
fflush(stdout);
|
||||
|
||||
len = mbedtls_snprintf((char *) buf, sizeof(buf), "MAIL FROM:<%s>\r\n", opt.mail_from);
|
||||
if (len < 0 || (size_t)len >= sizeof(buf)) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_snprintf encountered error or truncated output\n\n");
|
||||
goto exit;
|
||||
}
|
||||
ret = write_ssl_and_get_response(&ssl, buf, len);
|
||||
if (ret < 200 || ret > 299) {
|
||||
mbedtls_printf(" failed\n ! server responded with %d\n\n", ret);
|
||||
@ -740,6 +744,10 @@ usage:
|
||||
fflush(stdout);
|
||||
|
||||
len = mbedtls_snprintf((char *) buf, sizeof(buf), "RCPT TO:<%s>\r\n", opt.mail_to);
|
||||
if (len < 0 || (size_t)len >= sizeof(buf)) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_snprintf encountered error or truncated output\n\n");
|
||||
goto exit;
|
||||
}
|
||||
ret = write_ssl_and_get_response(&ssl, buf, len);
|
||||
if (ret < 200 || ret > 299) {
|
||||
mbedtls_printf(" failed\n ! server responded with %d\n\n", ret);
|
||||
@ -769,6 +777,10 @@ usage:
|
||||
"Mbed TLS mail client example.\r\n"
|
||||
"\r\n"
|
||||
"Enjoy!", opt.mail_from);
|
||||
if (len < 0 || (size_t)len >= sizeof(buf)) {
|
||||
mbedtls_printf(" failed\n ! mbedtls_snprintf encountered error or truncated output\n\n");
|
||||
goto exit;
|
||||
}
|
||||
ret = write_ssl_data(&ssl, buf, len);
|
||||
|
||||
len = sprintf((char *) buf, "\r\n.\r\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user