summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorSam Lang <sam.lang@inktank.com>2013-04-22 10:23:16 -0500
committerJeremy Allison <jra@samba.org>2013-04-24 23:58:43 +0200
commit727c611fe3c903d905871a46909ed1e7639add15 (patch)
tree5171ac1f23df5e6cf11764990248281ba46c472c /source4
parent301a1f919202c90c629a4926ebdf054b9f2fe1e8 (diff)
downloadsamba-727c611fe3c903d905871a46909ed1e7639add15.tar.gz
samba-727c611fe3c903d905871a46909ed1e7639add15.tar.bz2
samba-727c611fe3c903d905871a46909ed1e7639add15.zip
source4/libcli: Only set ctemp set on success
If open fails ctemp.out.name probably won't be valid and strdup will cause a segv. Only set the path if open succeeds. Signed-off-by: Sam Lang <sam.lang@inktank.com> Reviewed-by: Volker Lendecke <Volker.Lendecke@SerNet.DE> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Wed Apr 24 23:58:44 CEST 2013 on sn-devel-104
Diffstat (limited to 'source4')
-rw-r--r--source4/libcli/clifile.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/source4/libcli/clifile.c b/source4/libcli/clifile.c
index f5e02dd458..19288247c4 100644
--- a/source4/libcli/clifile.c
+++ b/source4/libcli/clifile.c
@@ -653,9 +653,10 @@ int smbcli_ctemp(struct smbcli_tree *tree, const char *path, char **tmp_path)
union smb_open open_parms;
TALLOC_CTX *mem_ctx;
NTSTATUS status;
+ int ret = -1;
mem_ctx = talloc_init("raw_open");
- if (!mem_ctx) return -1;
+ if (!mem_ctx) return ret;
open_parms.openx.level = RAW_OPEN_CTEMP;
open_parms.ctemp.in.attrib = 0;
@@ -663,12 +664,12 @@ int smbcli_ctemp(struct smbcli_tree *tree, const char *path, char **tmp_path)
open_parms.ctemp.in.write_time = 0;
status = smb_raw_open(tree, mem_ctx, &open_parms);
- if (tmp_path) {
- *tmp_path = strdup(open_parms.ctemp.out.name);
- }
- talloc_free(mem_ctx);
if (NT_STATUS_IS_OK(status)) {
- return open_parms.ctemp.out.file.fnum;
+ if (tmp_path) {
+ *tmp_path = strdup(open_parms.ctemp.out.name);
+ }
+ ret = open_parms.ctemp.out.file.fnum;
}
- return -1;
+ talloc_free(mem_ctx);
+ return ret;
}