Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit d38dbc7

Browse files
committed
apply correct casts in syscall_no_intercept calls
1 parent 5766039 commit d38dbc7

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

examples/syscall_logger.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
4747

48-
long log_fd;
48+
int log_fd;
4949

5050
static char buffer[0x20000];
5151
static size_t buffer_offset;
@@ -849,7 +849,8 @@ start(void)
849849
if (path == NULL)
850850
syscall_no_intercept(SYS_exit_group, 3);
851851

852-
log_fd = syscall_no_intercept(SYS_open, path, O_CREAT | O_RDWR, 0700);
852+
log_fd = (int)syscall_no_intercept(SYS_open,
853+
path, O_CREAT | O_RDWR, (mode_t)0700);
853854

854855
if (log_fd < 0)
855856
syscall_no_intercept(SYS_exit_group, 4);

src/entry.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ entry_point(void)
6666
* chars at a time. See syscall_hook_in_process_allowed below.
6767
*/
6868
static bool
69-
match_with_file_end(const char *expected, long fd)
69+
match_with_file_end(const char *expected, int fd)
7070
{
7171
char file_c; /* next character from file */
7272
const char *c; /* next character from the expected string */
@@ -76,7 +76,8 @@ match_with_file_end(const char *expected, long fd)
7676

7777
c = expected;
7878

79-
while (syscall_no_intercept(SYS_read, fd, &file_c, 1) == 1) {
79+
while (syscall_no_intercept(SYS_read, fd, &file_c, (size_t)1)
80+
== (ssize_t)1) {
8081
if (file_c == '\0') /* this probably never happens */
8182
break;
8283

@@ -98,15 +99,16 @@ match_with_file_end(const char *expected, long fd)
9899
int
99100
syscall_hook_in_process_allowed(void)
100101
{
101-
long fd;
102+
int fd;
102103
bool result;
103104
const char *filter;
104105

105106
filter = getenv("INTERCEPT_HOOK_CMDLINE_FILTER");
106107
if (filter == NULL)
107108
return 1;
108109

109-
fd = syscall_no_intercept(SYS_open, "/proc/self/cmdline", O_RDONLY, 0);
110+
fd = (int)syscall_no_intercept(SYS_open,
111+
"/proc/self/cmdline", O_RDONLY, (mode_t)0);
110112

111113
if (fd < 0)
112114
return 0;

src/intercept_desc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
* only be present in the original file.
5858
* Note on naming: memory has segments, the object file has sections.
5959
*/
60-
static long
60+
static int
6161
open_orig_file(const struct intercept_desc *desc)
6262
{
63-
long fd;
63+
int fd;
6464

6565
fd = syscall_no_intercept(SYS_open, desc->path, O_RDONLY);
6666

@@ -106,7 +106,7 @@ add_text_info(struct intercept_desc *desc, const Elf64_Shdr *header,
106106
* See: man elf
107107
*/
108108
static void
109-
find_sections(struct intercept_desc *desc, long fd)
109+
find_sections(struct intercept_desc *desc, int fd)
110110
{
111111
Elf64_Ehdr elf_header;
112112

@@ -293,7 +293,7 @@ mark_jump(const struct intercept_desc *desc, const unsigned char *addr)
293293
*/
294294
static void
295295
find_jumps_in_section_syms(struct intercept_desc *desc, Elf64_Shdr *section,
296-
long fd)
296+
int fd)
297297
{
298298
assert(section->sh_type == SHT_SYMTAB ||
299299
section->sh_type == SHT_DYNSYM);
@@ -344,7 +344,7 @@ find_jumps_in_section_syms(struct intercept_desc *desc, Elf64_Shdr *section,
344344
*/
345345
static void
346346
find_jumps_in_section_rela(struct intercept_desc *desc, Elf64_Shdr *section,
347-
long fd)
347+
int fd)
348348
{
349349
assert(section->sh_type == SHT_RELA);
350350

@@ -691,7 +691,7 @@ find_syscalls(struct intercept_desc *desc)
691691

692692
desc->count = 0;
693693

694-
long fd = open_orig_file(desc);
694+
int fd = open_orig_file(desc);
695695

696696
find_sections(desc, fd);
697697
debug_dump(

src/intercept_util.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
#include <sched.h>
4949
#include <linux/limits.h>
5050

51-
static long log_fd = -1;
51+
static int log_fd = -1;
5252

5353
void *
5454
xmmap_anon(size_t size)
5555
{
5656
void *addr = (void *) syscall_no_intercept(SYS_mmap,
5757
NULL, size,
5858
PROT_READ | PROT_WRITE,
59-
MAP_PRIVATE | MAP_ANON, -1, 0);
59+
MAP_PRIVATE | MAP_ANON, -1, (off_t)0);
6060

6161
if (addr == MAP_FAILED)
6262
xabort("xmmap_anon");
@@ -98,7 +98,7 @@ void
9898
xread(long fd, void *buffer, size_t size)
9999
{
100100
if (syscall_no_intercept(SYS_read, fd,
101-
(long)buffer, (long)size) != (long)size)
101+
buffer, size) != (ssize_t)size)
102102
xabort("xread");
103103
}
104104

@@ -130,7 +130,7 @@ intercept_setup_log(const char *path_base, const char *trunc)
130130

131131
intercept_log_close();
132132

133-
log_fd = syscall_no_intercept(SYS_open, path, flags, 0700);
133+
log_fd = (int)syscall_no_intercept(SYS_open, path, flags, (mode_t)0700);
134134

135135
if (log_fd < 0)
136136
xabort("setup_log");
@@ -1520,7 +1520,7 @@ intercept_log(const char *buffer, size_t len)
15201520
{
15211521
if (log_fd >= 0)
15221522
syscall_no_intercept(SYS_write, log_fd,
1523-
(long)buffer, (long)len);
1523+
buffer, len);
15241524
}
15251525

15261526
/*

0 commit comments

Comments
 (0)