From b4884dcff7362d585d93c3acf08e8c4835d918d0 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 10 Dec 2012 15:11:23 +0100 Subject: [PATCH] s3-libsmb: Fix possible comparsion problems. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This makes the code also easier to understand. Found by Coverity. Signed-off-by: Andreas Schneider Reviewed-by: Günther Deschner --- source3/libsmb/libsmb_printjob.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/source3/libsmb/libsmb_printjob.c b/source3/libsmb/libsmb_printjob.c index db46ceee9cb..173fa327d3e 100644 --- a/source3/libsmb/libsmb_printjob.c +++ b/source3/libsmb/libsmb_printjob.c @@ -93,6 +93,8 @@ SMBC_print_file_ctx(SMBCCTX *c_file, { SMBCFILE *fid1; SMBCFILE *fid2; + smbc_open_fn f_open1; + smbc_open_print_job_fn f_open_pj2; int bytes; int saverr; int tot_bytes = 0; @@ -113,18 +115,30 @@ SMBC_print_file_ctx(SMBCCTX *c_file, } /* Try to open the file for reading ... */ + f_open1 = smbc_getFunctionOpen(c_file); + if (f_open1 == NULL) { + errno = EINVAL; + TALLOC_FREE(frame); + return -1; + } - if ((long)(fid1 = smbc_getFunctionOpen(c_file)(c_file, fname, - O_RDONLY, 0666)) < 0) { - DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno)); + fid1 = f_open1(c_file, fname, O_RDONLY, 0666); + if (fid1 < 0) { + DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno)); TALLOC_FREE(frame); - return -1; /* smbc_open sets errno */ - } + return -1; /* smbc_open sets errno */ + } /* Now, try to open the printer file for writing */ + f_open_pj2 = smbc_getFunctionOpenPrintJob(c_print); + if (f_open_pj2 == NULL) { + errno = EINVAL; + TALLOC_FREE(frame); + return -1; + } - if ((long)(fid2 = smbc_getFunctionOpenPrintJob(c_print)(c_print, - printq)) < 0) { + fid2 = f_open_pj2(c_print, printq); + if (fid2 < 0) { saverr = errno; /* Save errno */ smbc_getFunctionClose(c_file)(c_file, fid1); errno = saverr; -- 2.34.1