Skip to content

Commit

Permalink
Fixed "Implicit conversion loses integer precision" warning
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed Dec 1, 2023
1 parent 8a40d6c commit fb97d2b
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 82 deletions.
6 changes: 3 additions & 3 deletions include/libsmb2-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ struct utf16 *utf8_to_utf16(const char *utf8);
/* Returns a string converted to UTF8 format. Use free() to release
* the utf8 string.
*/
const char *utf16_to_utf8(const uint16_t *str, int len);
const char *utf16_to_utf8(const uint16_t *str, size_t len);

/* Convert a win timestamp to a unix timeval */
void win_to_timeval(uint64_t smb2_time, struct smb2_timeval *tv);
Expand All @@ -303,7 +303,7 @@ void *smb2_alloc_data(struct smb2_context *smb2, void *memctx, size_t size);

struct smb2_iovec *smb2_add_iovector(struct smb2_context *smb2,
struct smb2_io_vectors *v,
uint8_t *buf, int len,
uint8_t *buf, size_t len,
void (*free)(void *));

int smb2_pad_to_64bit(struct smb2_context *smb2, struct smb2_io_vectors *v);
Expand All @@ -323,7 +323,7 @@ void smb2_free_iovector(struct smb2_context *smb2, struct smb2_io_vectors *v);
int smb2_decode_header(struct smb2_context *smb2, struct smb2_iovec *iov,
struct smb2_header *hdr);
int smb2_calc_signature(struct smb2_context *smb2, uint8_t *signature,
struct smb2_iovec *iov, int niov);
struct smb2_iovec *iov, size_t niov);

int smb2_set_uint8(struct smb2_iovec *iov, int offset, uint8_t value);
int smb2_set_uint16(struct smb2_iovec *iov, int offset, uint16_t value);
Expand Down
6 changes: 3 additions & 3 deletions include/smb2/smb2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
#endif

struct smb2_timeval {
uint32_t tv_sec;
uint64_t tv_sec;
uint32_t tv_usec;
};

Expand Down Expand Up @@ -647,11 +647,11 @@ struct smb2_ace {
* SMB2_DENIED_ALLOWED_CALLBACK_ACE_TYPE,
* SMB2_SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE
*/
int ad_len;
size_t ad_len;
char *ad_data;

/* raw blob, used for unknown ACE types */
int raw_len;
size_t raw_len;
char *raw_data;
};

Expand Down
41 changes: 21 additions & 20 deletions lib/aes128ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include "portable-endian.h"
#include "aes.h"

static void aes_ccm_generate_b0(unsigned char *nonce, int nlen,
int alen, int plen, int mlen,
static void aes_ccm_generate_b0(unsigned char *nonce, size_t nlen,
size_t alen, size_t plen, size_t mlen,
unsigned char *buf)
{
uint32_t len;
Expand All @@ -53,7 +53,7 @@ static void aes_ccm_generate_b0(unsigned char *nonce, int nlen,
memcpy(&buf[1], nonce, nlen);
}

static inline void bxory(unsigned char *b, unsigned char *y, int num)
static inline void bxory(unsigned char *b, unsigned char *y, size_t num)
{
int i;

Expand All @@ -63,10 +63,10 @@ static inline void bxory(unsigned char *b, unsigned char *y, int num)
}

static void ccm_generate_T(unsigned char *key,
unsigned char *nonce, int nlen,
unsigned char *aad, int alen,
unsigned char *p, int plen,
unsigned char *m, int mlen)
unsigned char *nonce, size_t nlen,
unsigned char *aad, size_t alen,
unsigned char *p, size_t plen,
unsigned char *m, size_t mlen)
{
unsigned char b[16], y[16];
uint16_t l;
Expand Down Expand Up @@ -116,8 +116,8 @@ static void ccm_generate_T(unsigned char *key,
memcpy(m, y, mlen);
}

static void ccm_generate_s(unsigned char *key, unsigned char *nonce, int nlen,
int plen, int i, unsigned char *s)
static void ccm_generate_s(unsigned char *key, unsigned char *nonce, size_t nlen,
size_t plen, int i, unsigned char *s)
{
uint32_t l;

Expand All @@ -133,10 +133,11 @@ static void ccm_generate_s(unsigned char *key, unsigned char *nonce, int nlen,
}

static void aes_ccm_crypt(unsigned char *key,
unsigned char *nonce, int nlen,
unsigned char *p, int plen)
unsigned char *nonce, size_t nlen,
unsigned char *p, size_t plen)
{
int j, l;
int j;
size_t l;
unsigned char s[16];

j = 0;
Expand All @@ -151,10 +152,10 @@ static void aes_ccm_crypt(unsigned char *key,
}

void aes128ccm_encrypt(unsigned char *key,
unsigned char *nonce, int nlen,
unsigned char *aad, int alen,
unsigned char *p, int plen,
unsigned char *m, int mlen)
unsigned char *nonce, size_t nlen,
unsigned char *aad, size_t alen,
unsigned char *p, size_t plen,
unsigned char *m, size_t mlen)
{
unsigned char s[16];

Expand All @@ -166,10 +167,10 @@ void aes128ccm_encrypt(unsigned char *key,
}

int aes128ccm_decrypt(unsigned char *key,
unsigned char *nonce, int nlen,
unsigned char *aad, int alen,
unsigned char *p, int plen,
unsigned char *m, int mlen)
unsigned char *nonce, size_t nlen,
unsigned char *aad, size_t alen,
unsigned char *p, size_t plen,
unsigned char *m, size_t mlen)
{
unsigned char s[16];
unsigned char tmp[16];
Expand Down
16 changes: 8 additions & 8 deletions lib/aes128ccm.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
void aes128ccm_encrypt(unsigned char *key,
unsigned char *nonce, int nlen,
unsigned char *aad, int alen,
unsigned char *p, int plen,
unsigned char *m, int mlen);
unsigned char *nonce, size_t nlen,
unsigned char *aad, size_t alen,
unsigned char *p, size_t plen,
unsigned char *m, size_t mlen);

int aes128ccm_decrypt(unsigned char *key,
unsigned char *nonce, int nlen,
unsigned char *aad, int alen,
unsigned char *p, int plen,
unsigned char *m, int mlen);
unsigned char *nonce, size_t nlen,
unsigned char *aad, size_t alen,
unsigned char *p, size_t plen,
unsigned char *m, size_t mlen);
2 changes: 1 addition & 1 deletion lib/dcerpc-lsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ RDL_DOMAINS_array_coder(struct dcerpc_context *dce,

entries = rdl->Entries;
offset = dcerpc_uint3264_coder(dce, pdu, iov, offset, &entries);
rdl->Entries = entries;
rdl->Entries = (uint32_t)entries;

if (dcerpc_pdu_direction(pdu) == DCERPC_DECODE) {
rdl->Domains = smb2_alloc_data(dcerpc_get_smb2_context(dce),
Expand Down
4 changes: 2 additions & 2 deletions lib/dcerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ dcerpc_call_async(struct dcerpc_context *dce,
memset(&req, 0, sizeof(struct smb2_ioctl_request));
req.ctl_code = SMB2_FSCTL_PIPE_TRANSCEIVE;
memcpy(req.file_id, dce->file_id, SMB2_FD_SIZE);
req.input_count = iov.len;
req.input_count = (uint32_t)iov.len;
req.input = iov.buf;
req.flags = SMB2_0_IOCTL_IS_FSCTL;

Expand Down Expand Up @@ -1663,7 +1663,7 @@ dcerpc_bind_async(struct dcerpc_context *dce, dcerpc_cb cb,
memset(&req, 0, sizeof(struct smb2_ioctl_request));
req.ctl_code = SMB2_FSCTL_PIPE_TRANSCEIVE;
memcpy(req.file_id, dce->file_id, SMB2_FD_SIZE);
req.input_count = iov.len;
req.input_count = (uint32_t)iov.len;
req.input = iov.buf;
req.flags = SMB2_0_IOCTL_IS_FSCTL;

Expand Down
10 changes: 5 additions & 5 deletions lib/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
*
*/
int
hmac (SHAversion whichSha, const unsigned char *text, int text_len,
const unsigned char *key, int key_len, uint8_t digest[USHAMaxHashSize])
hmac (SHAversion whichSha, const unsigned char *text, size_t text_len,
const unsigned char *key, size_t key_len, uint8_t digest[USHAMaxHashSize])
{
HMACContext ctx;
return hmacReset (&ctx, whichSha, key, key_len) ||
Expand Down Expand Up @@ -69,7 +69,7 @@ hmac (SHAversion whichSha, const unsigned char *text, int text_len,
*/
int
hmacReset (HMACContext * ctx, enum SHAversion whichSha,
const unsigned char *key, int key_len)
const unsigned char *key, size_t key_len)
{
int i, blocksize, hashsize;

Expand Down Expand Up @@ -155,7 +155,7 @@ hmacReset (HMACContext * ctx, enum SHAversion whichSha,
*
*/
int
hmacInput (HMACContext * ctx, const unsigned char *text, int text_len)
hmacInput (HMACContext * ctx, const unsigned char *text, size_t text_len)
{
if (!ctx)
return shaNull;
Expand Down Expand Up @@ -183,7 +183,7 @@ hmacInput (HMACContext * ctx, const unsigned char *text, int text_len)
* sha Error Code.
*/
int
hmacFinalBits (HMACContext * ctx, const uint8_t bits, unsigned int bitcount)
hmacFinalBits (HMACContext * ctx, const uint8_t bits, size_t bitcount)
{
if (!ctx)
return shaNull;
Expand Down
8 changes: 4 additions & 4 deletions lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ smb2_parse_args(struct smb2_context *smb2, const char *args)
return -1;
}
} else if (!strcmp(args, "timeout")) {
smb2->timeout = strtol(value, NULL, 10);
smb2->timeout = (int)strtol(value, NULL, 10);
} else {
smb2_set_error(smb2, "Unknown argument: %s", args);
return -1;
Expand Down Expand Up @@ -188,7 +188,7 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url)
char *ptr, *tmp, str[MAX_URL_SIZE];
char *args;
char *shared_folder;
int len_shared_folder;
size_t len_shared_folder;

if (strncmp(url, "smb://", 6)) {
smb2_set_error(smb2, "URL does not start with 'smb://'");
Expand Down Expand Up @@ -280,7 +280,7 @@ struct smb2_context *smb2_init_context(void)
int i, ret;
static int ctr;

srandom(time(NULL) ^ getpid() ^ ctr++);
srandom((unsigned)time(NULL) ^ getpid() ^ ctr++);

smb2 = calloc(1, sizeof(struct smb2_context));
if (smb2 == NULL) {
Expand Down Expand Up @@ -395,7 +395,7 @@ void smb2_free_iovector(struct smb2_context *smb2, struct smb2_io_vectors *v)

struct smb2_iovec *smb2_add_iovector(struct smb2_context *smb2,
struct smb2_io_vectors *v,
uint8_t *buf, int len,
uint8_t *buf, size_t len,
void (*free)(void *))
{
struct smb2_iovec *iov = &v->iov[v->niov];
Expand Down
4 changes: 2 additions & 2 deletions lib/ntlmssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
struct auth_data {
unsigned char *buf;
int len;
int allocated;
size_t allocated;

int neg_result;
unsigned char *ntlm_buf;
Expand Down Expand Up @@ -264,7 +264,7 @@ static int
NTOWFv2(const char *user, const char *password, const char *domain,
unsigned char ntlmv2_hash[16])
{
int i, len;
ssize_t i, len;
char *userdomain;
struct utf16 *utf16_userdomain = NULL;
unsigned char ntlm_hash[16];
Expand Down
34 changes: 17 additions & 17 deletions lib/sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,58 +243,58 @@ typedef struct HMACContext
/* SHA-1 */
extern int SHA1Reset (SHA1Context *);
extern int SHA1Input (SHA1Context *, const uint8_t * bytes,
unsigned int bytecount);
size_t bytecount);
extern int SHA1FinalBits (SHA1Context *, const uint8_t bits,
unsigned int bitcount);
size_t bitcount);
extern int SHA1Result (SHA1Context *, uint8_t Message_Digest[SHA1HashSize]);
#endif

#if defined(USE_SHA224) && USE_SHA224
/* SHA-224 */
extern int SHA224Reset (SHA224Context *);
extern int SHA224Input (SHA224Context *, const uint8_t * bytes,
unsigned int bytecount);
size_t bytecount);
extern int SHA224FinalBits (SHA224Context *, const uint8_t bits,
unsigned int bitcount);
size_t bitcount);
extern int SHA224Result (SHA224Context *,
uint8_t Message_Digest[SHA224HashSize]);
#endif

/* SHA-256 */
extern int SHA256Reset (SHA256Context *);
extern int SHA256Input (SHA256Context *, const uint8_t * bytes,
unsigned int bytecount);
size_t bytecount);
extern int SHA256FinalBits (SHA256Context *, const uint8_t bits,
unsigned int bitcount);
size_t bitcount);
extern int SHA256Result (SHA256Context *,
uint8_t Message_Digest[SHA256HashSize]);

#if defined(USE_SHA384_SHA512) && USE_SHA384_SHA512
/* SHA-384 */
extern int SHA384Reset (SHA384Context *);
extern int SHA384Input (SHA384Context *, const uint8_t * bytes,
unsigned int bytecount);
size_t bytecount);
extern int SHA384FinalBits (SHA384Context *, const uint8_t bits,
unsigned int bitcount);
size_t bitcount);
extern int SHA384Result (SHA384Context *,
uint8_t Message_Digest[SHA384HashSize]);

/* SHA-512 */
extern int SHA512Reset (SHA512Context *);
extern int SHA512Input (SHA512Context *, const uint8_t * bytes,
unsigned int bytecount);
size_t bytecount);
extern int SHA512FinalBits (SHA512Context *, const uint8_t bits,
unsigned int bitcount);
size_t bitcount);
extern int SHA512Result (SHA512Context *,
uint8_t Message_Digest[SHA512HashSize]);
#endif

/* Unified SHA functions, chosen by whichSha */
extern int USHAReset (USHAContext *, SHAversion whichSha);
extern int USHAInput (USHAContext *,
const uint8_t * bytes, unsigned int bytecount);
const uint8_t * bytes, size_t bytecount);
extern int USHAFinalBits (USHAContext *,
const uint8_t bits, unsigned int bitcount);
const uint8_t bits, size_t bitcount);
extern int USHAResult (USHAContext *,
uint8_t Message_Digest[USHAMaxHashSize]);
extern int USHABlockSize (enum SHAversion whichSha);
Expand All @@ -308,9 +308,9 @@ extern int USHAHashSizeBits (enum SHAversion whichSha);
*/
extern int hmac (SHAversion whichSha, /* which SHA algorithm to use */
const unsigned char *text, /* pointer to data stream */
int text_len, /* length of data stream */
size_t text_len, /* length of data stream */
const unsigned char *key, /* pointer to authentication key */
int key_len, /* length of authentication key */
size_t key_len, /* length of authentication key */
uint8_t digest[USHAMaxHashSize]); /* caller digest to fill in */

/*
Expand All @@ -319,12 +319,12 @@ extern int hmac (SHAversion whichSha, /* which SHA algorithm to use */
* This interface allows any length of text input to be used.
*/
extern int hmacReset (HMACContext * ctx, enum SHAversion whichSha,
const unsigned char *key, int key_len);
const unsigned char *key, size_t key_len);
extern int hmacInput (HMACContext * ctx, const unsigned char *text,
int text_len);
size_t text_len);

extern int hmacFinalBits (HMACContext * ctx, const uint8_t bits,
unsigned int bitcount);
size_t bitcount);
extern int hmacResult (HMACContext * ctx, uint8_t *digest);

#endif /* _SHA_H_ */
4 changes: 2 additions & 2 deletions lib/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ SHA1Reset (SHA1Context * context)
*/
int
SHA1Input (SHA1Context * context,
const uint8_t * message_array, unsigned length)
const uint8_t * message_array, size_t length)
{
uint32_t addTemp;

Expand Down Expand Up @@ -177,7 +177,7 @@ SHA1Input (SHA1Context * context,
*/
int
SHA1FinalBits (SHA1Context * context, const uint8_t message_bits,
unsigned int length)
size_t length)
{
uint32_t addTemp;
uint8_t masks[8] = {
Expand Down
Loading

0 comments on commit fb97d2b

Please sign in to comment.