Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tm-threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ static int SetCPUAffinitySet(cpu_set_t *cs)
int r = thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY,
(void*)cs, THREAD_AFFINITY_POLICY_COUNT);
#else
pid_t tid = syscall(SYS_gettid);
pid_t tid = (pid_t)syscall(SYS_gettid);
int r = sched_setaffinity(tid, sizeof(cpu_set_t), cs);
#endif /* OS_FREEBSD */

Expand Down
10 changes: 5 additions & 5 deletions src/unix-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ typedef struct UnixCommand_ {
static int UnixNew(UnixCommand * this)
{
struct sockaddr_un addr;
int len;
socklen_t len;
int ret;
int on = 1;
char sockettarget[PATH_MAX];
Expand Down Expand Up @@ -161,7 +161,7 @@ static int UnixNew(UnixCommand * this)
addr.sun_family = AF_UNIX;
strlcpy(addr.sun_path, sockettarget, sizeof(addr.sun_path));
addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
len = strlen(addr.sun_path) + sizeof(addr.sun_family) + 1;
len = (socklen_t)(strlen(addr.sun_path) + sizeof(addr.sun_family) + 1);

/* create socket */
this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
Expand Down Expand Up @@ -335,7 +335,7 @@ static int UnixCommandAccept(UnixCommand *this)
json_error_t jerror;
int client;
int client_version;
int ret;
ssize_t ret;
UnixClient *uclient = NULL;

/* accept client socket */
Expand Down Expand Up @@ -537,7 +537,7 @@ static int UnixCommandExecute(UnixCommand * this, char *command, UnixClient *cli
static void UnixCommandRun(UnixCommand * this, UnixClient *client)
{
char buffer[4096];
int ret;
ssize_t ret;
if (client->version <= UNIX_PROTO_V1) {
ret = recv(client->fd, buffer, sizeof(buffer) - 1, 0);
if (ret <= 0) {
Expand Down Expand Up @@ -695,7 +695,7 @@ static TmEcode UnixManagerUptimeCommand(json_t *cmd,
json_t *server_msg, void *data)
{
SCEnter();
int uptime;
time_t uptime;
UnixCommand *ucmd = (UnixCommand *)data;

uptime = time(NULL) - ucmd->start_timestamp;
Expand Down
10 changes: 5 additions & 5 deletions src/util-affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void BuildCpusetWithCallback(const char *name, ConfNode *node,
ConfNode *lnode;
TAILQ_FOREACH(lnode, &node->head, next) {
int i;
long int a,b;
int a, b;
int stop = 0;
int max = UtilCpuGetNumProcessorsOnline() - 1;
if (!strcmp(lnode->val, "all")) {
Expand All @@ -111,12 +111,12 @@ void BuildCpusetWithCallback(const char *name, ConfNode *node,
} else if (strchr(lnode->val, '-') != NULL) {
char *sep = strchr(lnode->val, '-');
char *end;
a = strtoul(lnode->val, &end, 10);
a = (int)strtoul(lnode->val, &end, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit odd, downcasting strtoul to int... should we just use atoi? Or one of our parsing wrappers perhaps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying StringParseUint32

if (end != sep) {
SCLogError("%s: invalid cpu range (start invalid): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
}
b = strtol(sep + 1, &end, 10);
b = (int)strtol(sep + 1, &end, 10);
if (end != sep + strlen(sep)) {
SCLogError("%s: invalid cpu range (end invalid): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
Expand All @@ -126,12 +126,12 @@ void BuildCpusetWithCallback(const char *name, ConfNode *node,
exit(EXIT_FAILURE);
}
if (b > max) {
SCLogError("%s: upper bound (%ld) of cpu set is too high, only %d cpu(s)", name, b,
SCLogError("%s: upper bound (%d) of cpu set is too high, only %d cpu(s)", name, b,
max + 1);
}
} else {
char *end;
a = strtoul(lnode->val, &end, 10);
a = (int)strtoul(lnode->val, &end, 10);
if (end != lnode->val + strlen(lnode->val)) {
SCLogError("%s: invalid cpu range (not an integer): \"%s\"", name, lnode->val);
exit(EXIT_FAILURE);
Expand Down
4 changes: 2 additions & 2 deletions src/util-byte.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int ByteExtractString(uint64_t *res, int base, size_t len, const char *str, bool
return -1;
}

return (endptr - ptr);
return (int)(endptr - ptr);
}

int ByteExtractStringUint64(uint64_t *res, int base, size_t len, const char *str)
Expand Down Expand Up @@ -531,7 +531,7 @@ int ByteExtractStringSigned(int64_t *res, int base, size_t len, const char *str,

//fprintf(stderr, "ByteExtractStringSigned: Extracted base %d: 0x%" PRIx64 "\n", base, *res);

return (endptr - ptr);
return (int)(endptr - ptr);
}

int ByteExtractStringInt64(int64_t *res, int base, size_t len, const char *str)
Expand Down
8 changes: 4 additions & 4 deletions src/util-classification-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ uint32_t SCClassConfClasstypeHashFunc(HashTable *ht, void *data, uint16_t datale
{
SCClassConfClasstype *ct = (SCClassConfClasstype *)data;
uint32_t hash = 0;
int i = 0;
size_t i = 0;

int len = strlen(ct->classtype);
size_t len = strlen(ct->classtype);

for (i = 0; i < len; i++)
hash += u8_tolower((unsigned char)(ct->classtype)[i]);
Expand Down Expand Up @@ -478,8 +478,8 @@ char SCClassConfClasstypeHashCompareFunc(void *data1, uint16_t datalen1,
{
SCClassConfClasstype *ct1 = (SCClassConfClasstype *)data1;
SCClassConfClasstype *ct2 = (SCClassConfClasstype *)data2;
int len1 = 0;
int len2 = 0;
size_t len1 = 0;
size_t len2 = 0;

if (ct1 == NULL || ct2 == NULL)
return 0;
Expand Down
18 changes: 9 additions & 9 deletions src/util-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,25 +286,25 @@ static const char *SCTransformModule(const char *module_name, int *dn_len)
* app-layer-*
*/
if (strncmp("tm-", module_name, 3) == 0) {
*dn_len = strlen(module_name) - 3;
*dn_len = (int)strlen(module_name) - 3;
return module_name + 3;
} else if (strncmp("util-", module_name, 5) == 0) {
*dn_len = strlen(module_name) - 5;
*dn_len = (int)strlen(module_name) - 5;
return module_name + 5;
} else if (strncmp("source-pcap-file", module_name, 16) == 0) {
*dn_len = strlen("pcap");
*dn_len = (int)strlen("pcap");
return "pcap";
} else if (strncmp("source-", module_name, 7) == 0) {
*dn_len = strlen(module_name) - 7;
*dn_len = (int)strlen(module_name) - 7;
return module_name + 7;
} else if (strncmp("runmode-", module_name, 8) == 0) {
*dn_len = strlen(module_name) - 8;
*dn_len = (int)strlen(module_name) - 8;
return module_name + 8;
} else if (strncmp("app-layer-", module_name, 10) == 0) {
*dn_len = strlen(module_name);
*dn_len = (int)strlen(module_name);
return module_name;
} else if (strncmp("detect-engine", module_name, 13) == 0) {
*dn_len = strlen("detect");
*dn_len = (int)strlen("detect");
return "detect";
}

Expand All @@ -319,9 +319,9 @@ static const char *SCTransformModule(const char *module_name, int *dn_len)
}

if (seg_cnt < transform_max_segs)
*dn_len = strlen(module_name);
*dn_len = (int)strlen(module_name);
else
*dn_len = last - module_name;
*dn_len = (int)(last - module_name);

return module_name;
}
Expand Down
16 changes: 8 additions & 8 deletions src/util-fmemopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ static fpos_t SeekFn(void *handler, fpos_t offset, int whence)
*/
static int ReadFn(void *handler, char *buf, int size)
{
size_t count = 0;
int count = 0;
SCFmem *mem = handler;
size_t available = mem->size - mem->pos;
int is_eof = 0;

if (size < 0) return - 1;

if ((size_t)size > available) {
size = available;
if (available < INT_MAX && size > (int)available) {
size = (int)available;
} else {
is_eof = 1;
}

while (count < (size_t)size)
while (count < size)
buf[count++] = mem->buffer[mem->pos++];

if (is_eof == 1)
Expand All @@ -148,16 +148,16 @@ static int ReadFn(void *handler, char *buf, int size)
*/
static int WriteFn(void *handler, const char *buf, int size)
{
size_t count = 0;
int count = 0;
SCFmem *mem = handler;
size_t available = mem->size - mem->pos;

if (size < 0) return - 1;

if ((size_t)size > available)
size = available;
if (available < INT_MAX && size > (int)available)
size = (int)available;

while (count < (size_t)size)
while (count < size)
mem->buffer[mem->pos++] = buf[count++];

return count;
Expand Down
8 changes: 4 additions & 4 deletions src/util-ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ bool IPv4AddressStringIsValid(const char *str)

memset(&addr, 0, sizeof(addr));

uint32_t len = strlen(str);
uint32_t i = 0;
size_t len = strlen(str);
size_t i = 0;
for (i = 0; i < len; i++) {
if (!(str[i] == '.' || isdigit(str[i]))) {
return false;
Expand Down Expand Up @@ -85,8 +85,8 @@ bool IPv6AddressStringIsValid(const char *str)
int sep = 0;
bool colon_seen = false;

uint32_t len = strlen(str);
uint32_t i = 0;
size_t len = strlen(str);
size_t i = 0;
for (i = 0; i < len && str[i] != 0; i++) {
if (!(str[i] == '.' || str[i] == ':' ||
isxdigit(str[i])))
Expand Down
4 changes: 2 additions & 2 deletions src/util-ja3.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

typedef struct JA3Buffer_ {
char *data;
size_t size;
size_t used;
uint32_t size;
uint32_t used;
} JA3Buffer;

JA3Buffer *Ja3BufferInit(void);
Expand Down
6 changes: 3 additions & 3 deletions src/util-landlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ void LandlockSandboxing(SCInstance *suri)
static inline int landlock_create_ruleset(
const struct landlock_ruleset_attr *const attr, const size_t size, const __u32 flags)
{
return syscall(__NR_landlock_create_ruleset, attr, size, flags);
return (int)syscall(__NR_landlock_create_ruleset, attr, size, flags);
}
#endif

#ifndef landlock_add_rule
static inline int landlock_add_rule(const int ruleset_fd, const enum landlock_rule_type rule_type,
const void *const rule_attr, const __u32 flags)
{
return syscall(__NR_landlock_add_rule, ruleset_fd, rule_type, rule_attr, flags);
return (int)syscall(__NR_landlock_add_rule, ruleset_fd, rule_type, rule_attr, flags);
}
#endif

#ifndef landlock_restrict_self
static inline int landlock_restrict_self(const int ruleset_fd, const __u32 flags)
{
return syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
return (int)syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/util-logopenfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ static bool LogFileThreadedName(
* for update
*/
dot = strrchr(original_name, '.');
int dotpos = dot - original_name;
ptrdiff_t dotpos = dot - original_name;
tname[dotpos] = '\0';
char *ext = tname + dotpos + 1;
if (strlen(tname) && strlen(ext)) {
Expand Down
10 changes: 5 additions & 5 deletions src/util-lua-hashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static int LuaHashLibSha256Update(lua_State *L)
}
size_t data_len;
const char *data = luaL_checklstring(L, 2, &data_len);
SCSha256Update(*hasher, (const uint8_t *)data, data_len);
SCSha256Update(*hasher, (const uint8_t *)data, (uint32_t)data_len);
return 0;
}

Expand Down Expand Up @@ -123,7 +123,7 @@ static int LuaHashLibSha256Digest(lua_State *L)
size_t buf_len;
const char *input = luaL_checklstring(L, 1, &buf_len);

size_t output_len = SC_SHA256_LEN;
uint32_t output_len = SC_SHA256_LEN;
uint8_t output[output_len];
if (!SCSha256HashBuffer((uint8_t *)input, (uint32_t)buf_len, output, output_len)) {
return luaL_error(L, "sha256 hashing failed");
Expand Down Expand Up @@ -178,7 +178,7 @@ static int LuaHashLibSha1Update(lua_State *L)

size_t data_len;
const char *data = luaL_checklstring(L, 2, &data_len);
SCSha1Update(*hasher, (const uint8_t *)data, data_len);
SCSha1Update(*hasher, (const uint8_t *)data, (uint32_t)data_len);
return 0;
}

Expand Down Expand Up @@ -280,7 +280,7 @@ static int LuaHashLibMd5Update(lua_State *L)

size_t data_len;
const char *data = luaL_checklstring(L, 2, &data_len);
SCMd5Update(*hasher, (const uint8_t *)data, data_len);
SCMd5Update(*hasher, (const uint8_t *)data, (uint32_t)data_len);
return 0;
}

Expand Down Expand Up @@ -344,7 +344,7 @@ static int LuaHashLibMd5HexDigest(lua_State *L)
const char *input = luaL_checklstring(L, 1, &buf_len);

char output[SC_MD5_HEX_LEN + 1];
if (!SCMd5HashBufferToHex((uint8_t *)input, (size_t)buf_len, output, sizeof(output))) {
if (!SCMd5HashBufferToHex((uint8_t *)input, (uint32_t)buf_len, output, sizeof(output))) {
return luaL_error(L, "md5 hashing failed");
}

Expand Down
3 changes: 2 additions & 1 deletion src/util-lua-sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ typedef struct SCLuaSbState {
/* Execution Limits */
uint64_t instruction_count;
uint64_t instruction_limit;
uint64_t hook_instruction_count;
// used by lua_sethook
int hook_instruction_count;

/* Errors. */
bool blocked_function_error;
Expand Down
6 changes: 3 additions & 3 deletions src/util-proto-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ static uint32_t ProtoNameHashFunc(HashTable *ht, void *data, uint16_t datalen)
* as the proto number is not used for lookups
*/
ProtoNameHashEntry *p = (ProtoNameHashEntry *)data;
return StringHashDjb2((uint8_t *)p->name, strlen(p->name)) % ht->array_size;
return StringHashDjb2((uint8_t *)p->name, (uint32_t)strlen(p->name)) % ht->array_size;
}

static char ProtoNameHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
Expand All @@ -375,8 +375,8 @@ static char ProtoNameHashCompareFunc(void *data1, uint16_t datalen1, void *data2
if (p1->name == NULL || p2->name == NULL)
return 0;

int len1 = strlen(p1->name);
int len2 = strlen(p2->name);
size_t len1 = strlen(p1->name);
size_t len2 = strlen(p2->name);

return len1 == len2 && memcmp(p1->name, p2->name, len1) == 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/util-random.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static long int RandomGetClock(void)
clock_gettime(CLOCK_REALTIME, &ts);

// coverity[dont_call : FALSE]
srandom(ts.tv_nsec ^ ts.tv_sec);
srandom((unsigned int)(ts.tv_nsec ^ ts.tv_sec));
long int value = random();
return value;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ long int RandomGet(void)
return 0;

long int value = 0;
int ret = getrandom(&value, sizeof(value), 0);
ssize_t ret = getrandom(&value, sizeof(value), 0);
/* ret should be sizeof(value), but if it is > 0 and < sizeof(value)
* it's still better than nothing so we return what we have */
if (ret <= 0) {
Expand Down
Loading
Loading