From bbc1c93c14f71acae5d3f1efea17a6c24e244296 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 29 Aug 2012 16:32:29 -0500 Subject: Check the return from snprintf --- socket-sucker.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/socket-sucker.c b/socket-sucker.c index 7a1e82f..d711cb0 100644 --- a/socket-sucker.c +++ b/socket-sucker.c @@ -41,7 +41,12 @@ main (int argc, char * argv[]) } serv_addr.sun_family = AF_UNIX; - snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path), "%s/%s", home, ".freerdp-socket"); + + int printsize = snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path) - 1, "%s/%s", home, ".freerdp-socket"); + if (printsize > sizeof(serv_addr.sun_path) - 1) { + return -1; + } + servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family); if ((socket_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { -- cgit v1.2.3 From dd7dda9f5b5626ef84510f317ea2929744680557 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 29 Aug 2012 16:34:01 -0500 Subject: Checking the return values on read and write better --- socket-sucker.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/socket-sucker.c b/socket-sucker.c index d711cb0..54aee32 100644 --- a/socket-sucker.c +++ b/socket-sucker.c @@ -62,11 +62,14 @@ main (int argc, char * argv[]) int out = 0; in = read(socket_fd, buffer, BUFFER_SIZE); - out = write(1, buffer, in); + + if (in > 0) { + out = write(1, buffer, in); + } close(socket_fd); - if (in == 0) { + if (in > 0 && out > 0) { return 0; } else { return -1; -- cgit v1.2.3 From b74d1cfe5d828157bc000749c06e55a7740a57ee Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 29 Aug 2012 16:35:47 -0500 Subject: Compiling with PIE --- Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile.am b/Makefile.am index df8fa8e..bf4b300 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,11 @@ pkglibexec_PROGRAMS = \ socket-sucker socket_sucker_SOURCES = \ socket-sucker.c +socket_sucker_CFLAGS = \ + -Wall -Werror \ + -fPIE +socket_sucker_LDFLAGS = \ + -pie EXTRA_DIST = \ $(pam_session_DATA) \ -- cgit v1.2.3 -- cgit v1.2.3 From ff6a857303006d1e9e2c920c39cf3a1bca30871f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 29 Aug 2012 16:58:05 -0500 Subject: Check to ensure we wrote something --- socket-sucker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socket-sucker.c b/socket-sucker.c index 54aee32..35424a6 100644 --- a/socket-sucker.c +++ b/socket-sucker.c @@ -43,7 +43,7 @@ main (int argc, char * argv[]) serv_addr.sun_family = AF_UNIX; int printsize = snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path) - 1, "%s/%s", home, ".freerdp-socket"); - if (printsize > sizeof(serv_addr.sun_path) - 1) { + if (printsize > sizeof(serv_addr.sun_path) - 1 || printsize < 0) { return -1; } -- cgit v1.2.3