From 9ef3b9ec685c5a3f84c26a190939261287c417fc Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Wed, 4 Apr 2018 20:37:13 +0100 Subject: [PATCH] dtspcd: Cov 89547, 175089 --- cde/programs/dtspcd/main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cde/programs/dtspcd/main.c b/cde/programs/dtspcd/main.c index 4ca6a5f7..680745d1 100644 --- a/cde/programs/dtspcd/main.c +++ b/cde/programs/dtspcd/main.c @@ -507,6 +507,7 @@ int Client_Register(protocol_request_ptr prot) char *spc_prefix = "/.SPC_"; char *spc_suffix; char tmpnam_buf[L_tmpnam + 1]; + size_t buffsize; print_protocol_request((XeString)"--> REGISTER", prot); prot->channel=0; @@ -563,10 +564,10 @@ int Client_Register(protocol_request_ptr prot) spc_suffix = basename(tmpnam_buf); /* Don't free result - not alloc'd! */ /* Allocate space for tmppath, spc_prefix, and spc_suffix. */ - tmpfile = (char *)malloc((strlen(tmppath) + strlen(spc_prefix) + - strlen(spc_suffix) + 1) * sizeof(char)); + buffsize = strlen(tmppath) + strlen(spc_prefix) + strlen(spc_suffix) + 1; + tmpfile = (char *)malloc(buffsize); if(tmpfile) { - snprintf(tmpfile, sizeof(tmpfile), "%s%s%s", tmppath, spc_prefix, spc_suffix); + snprintf(tmpfile, buffsize, "%s%s%s", tmppath, spc_prefix, spc_suffix); } } else { @@ -653,8 +654,10 @@ int Client_Register(protocol_request_ptr prot) SPC_LocalHostinfo()); prot=SPC_Filter_Connection(client_connection, NULL, REGISTER, TRUE); - if(prot==SPC_ERROR) + if(prot==SPC_ERROR) { + XeFree(tmpfile); return(SPC_ERROR); + } sprintf(buffer, (XeString)"--> REGISTER (%s)", netfile); print_protocol_request(buffer, prot); SPC_Free_Protocol_Ptr(prot); -- 2.25.1