From 3642390b3c53f469916e02f7a1bebe4ebd0aeba3 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 898c43cef8d4e57740227743794700f0d7fa2ca2 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 58791bb4a55905588ed5378948ce536523b331a8 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 e2d8b821e5047519f673462b6301e8d19ad170ce 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