From 25c40c9af97782c9d475e765d50eaac071fd7d91 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 15 Jan 2018 20:43:34 +0100 Subject: SMB: fix numeric constant suffix and variable types 1. don't use "ULL" suffix since unsupported in older MSVC 2. use curl_off_t instead of custom long long ifdefs 3. make get_posix_time() not do unaligned data access Fixes #2211 Closes #2240 Reported-by: Chester Liu --- lib/smb.c | 29 ++++++++--------------------- lib/smb.h | 33 ++++++++++----------------------- 2 files changed, 18 insertions(+), 44 deletions(-) diff --git a/lib/smb.c b/lib/smb.c index efcfd2da2..6cb4083bb 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -6,7 +6,7 @@ * \___|\___/|_| \_\_____| * * Copyright (C) 2014, Bill Nagel , Exacq Technologies - * Copyright (C) 2016-2017, Daniel Stenberg, , et al. + * Copyright (C) 2016-2018, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -146,19 +146,12 @@ static unsigned int smb_swap32(unsigned int x) ((x >> 24) & 0xff); } -#ifdef HAVE_LONGLONG -static unsigned long long smb_swap64(unsigned long long x) +static curl_off_t smb_swap64(curl_off_t x) { - return ((unsigned long long) smb_swap32((unsigned int) x) << 32) | + return ((curl_off_t) smb_swap32((unsigned int) x) << 32) | smb_swap32((unsigned int) (x >> 32)); } -#else -static unsigned __int64 smb_swap64(unsigned __int64 x) -{ - return ((unsigned __int64) smb_swap32((unsigned int) x) << 32) | - smb_swap32((unsigned int) (x >> 32)); -} -#endif + #else # define smb_swap16(x) (x) # define smb_swap32(x) (x) @@ -719,17 +712,11 @@ static CURLcode smb_connection_state(struct connectdata *conn, bool *done) * Convert a timestamp from the Windows world (100 nsec units from * 1 Jan 1601) to Posix time. */ -static void get_posix_time(long *_out, const void *_in) +static void get_posix_time(long *out, curl_off_t timestamp) { -#ifdef HAVE_LONGLONG - long long timestamp = *(long long *) _in; -#else - unsigned __int64 timestamp = *(unsigned __int64 *) _in; -#endif - - timestamp -= 116444736000000000ULL; + timestamp -= 116444736000000000; timestamp /= 10000000; - *_out = (long) timestamp; + *out = (long) timestamp; } static CURLcode smb_request_state(struct connectdata *conn, bool *done) @@ -798,7 +785,7 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done) conn->data->req.size = smb_swap64(smb_m->end_of_file); Curl_pgrsSetDownloadSize(conn->data, conn->data->req.size); if(conn->data->set.get_filetime) - get_posix_time(&conn->data->info.filetime, &smb_m->last_change_time); + get_posix_time(&conn->data->info.filetime, smb_m->last_change_time); next_state = SMB_DOWNLOAD; } break; diff --git a/lib/smb.h b/lib/smb.h index 1a4f66e5a..c3ee7ae03 100644 --- a/lib/smb.h +++ b/lib/smb.h @@ -8,6 +8,7 @@ * \___|\___/|_| \_\_____| * * Copyright (C) 2014, Bill Nagel , Exacq Technologies + * Copyright (C) 2018, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -165,11 +166,7 @@ struct smb_nt_create { unsigned int flags; unsigned int root_fid; unsigned int access; -#ifdef HAVE_LONGLONG - unsigned long long allocation_size; -#else - unsigned __int64 allocation_size; -#endif + curl_off_t allocation_size; unsigned int ext_file_attributes; unsigned int share_access; unsigned int create_disposition; @@ -187,25 +184,15 @@ struct smb_nt_create_response { unsigned char op_lock_level; unsigned short fid; unsigned int create_disposition; -#ifdef HAVE_LONGLONG - unsigned long long create_time; - unsigned long long last_access_time; - unsigned long long last_write_time; - unsigned long long last_change_time; -#else - unsigned __int64 create_time; - unsigned __int64 last_access_time; - unsigned __int64 last_write_time; - unsigned __int64 last_change_time; -#endif + + curl_off_t create_time; + curl_off_t last_access_time; + curl_off_t last_write_time; + curl_off_t last_change_time; unsigned int ext_file_attributes; -#ifdef HAVE_LONGLONG - unsigned long long allocation_size; - unsigned long long end_of_file; -#else - unsigned __int64 allocation_size; - unsigned __int64 end_of_file; -#endif + curl_off_t allocation_size; + curl_off_t end_of_file; + } PACK; struct smb_read { -- cgit v1.2.3