Skip to content

Commit

Permalink
Attempts to avoid uninitialized memory due to connection errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
atheriel committed Jun 20, 2019
1 parent 3889e78 commit a1ea9be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions src/connection.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#include <amqp.h>
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a1ea9be

Please sign in to comment.