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 b220443
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 83 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
8 changes: 4 additions & 4 deletions include/smb2/smb2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extern "C" {
#endif

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

#define SMB2_ERROR_REPLY_SIZE 9
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
22 changes: 17 additions & 5 deletions lib/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
* various SHA algorithms.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#include "compat.h"

#include "sha.h"
Expand Down Expand Up @@ -38,8 +50,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 +81,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 +167,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 +195,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;
int64_t i, len;
char *userdomain;
struct utf16 *utf16_userdomain = NULL;
unsigned char ntlm_hash[16];
Expand Down
Loading

0 comments on commit b220443

Please sign in to comment.