diff --git a/NEWS.md b/NEWS.md index 51ff68d..dc6a646 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ - Tests requiring a local RMQ server will now be skipped unless one is detected. - Fixes an issue where `amqp_properties()` would not handle missing names correctly. +- Fixes an issue where connection errors could sometimes encounter uninitialized + memory. # longears 0.1.0 (2019-06-06) diff --git a/src/connection.c b/src/connection.c index f8085d3..e9be3c9 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -9,7 +10,7 @@ #include "connection.h" #include "utils.h" -int connect(connection *conn, char *buffer, size_t len); +static int connect(connection *conn, char *buffer, size_t len); static void R_finalize_amqp_connection(SEXP ptr) { @@ -59,6 +60,10 @@ SEXP R_amqp_connect(SEXP host, SEXP port, SEXP vhost, SEXP username, } char msg[120]; + /* Although this should not really be necessary, it seems that under some + * connection error conditions the stack-allocated array above will trigger + * errors due to uninitialized memory. */ + memset(msg, 0, 120); if (connect(conn, msg, 120) < 0) { amqp_destroy_connection(conn->conn); free(conn); @@ -132,7 +137,7 @@ SEXP R_amqp_disconnect(SEXP ptr) return R_NilValue; } -int connect(connection *conn, char *buffer, size_t len) +static int connect(connection *conn, char *buffer, size_t len) { // Assume conn->conn is valid. if (conn->is_connected) return 0;