From a3118e8c6826349b3fc54da3850d6dea994a3a35 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 16 Jan 1997 21:58:40 +0000 Subject: Sweep through the tree fixing mmap() usage: - Use MAP_FAILED instead of the constant -1 to indicate failure (required by POSIX). - Removed flag arguments of '0' (required by POSIX). - Fixed code which expected an error return of 0. - Fixed code which thought any address with the high bit set was an error. - Check for failure where no checks were present. Discussed with: bde --- usr.sbin/config/main.c | 8 ++++---- usr.sbin/ctm/mkCTM/mkctm.c | 6 +++--- usr.sbin/kvm_mkdb/nlist.c | 3 +++ usr.sbin/rpc.statd/file.c | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index 4d3cccb..3e6778f 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -405,11 +405,11 @@ moveifchanged(const char *from_name, const char *to_name) tsize = (size_t)from_sb.st_size; if (!changed) { - p = mmap(NULL, tsize, PROT_READ, 0, from_fd, (off_t)0); - if ((long)p == -1) + p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0); + if (p == MAP_FAILED) err(EX_OSERR, "mmap %s", from_name); - q = mmap(NULL, tsize, PROT_READ, 0, to_fd, (off_t)0); - if ((long)q == -1) + q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0); + if (q == MAP_FAILED) err(EX_OSERR, "mmap %s", to_name); changed = memcmp(p, q, tsize); diff --git a/usr.sbin/ctm/mkCTM/mkctm.c b/usr.sbin/ctm/mkCTM/mkctm.c index 24c3aaa..698d114 100644 --- a/usr.sbin/ctm/mkCTM/mkctm.c +++ b/usr.sbin/ctm/mkCTM/mkctm.c @@ -179,11 +179,11 @@ Equ(const char *dir1, const char *dir2, const char *name, struct dirent *de) } #endif p1=mmap(0, s1.st_size, PROT_READ, MAP_PRIVATE, fd1, 0); - if ((int)p1 == -1) { perror(buf1); exit(3); } + if (p1 == (u_char *)MAP_FAILED) { perror(buf1); exit(3); } close(fd1); p2=mmap(0, s2.st_size, PROT_READ, MAP_PRIVATE, fd2, 0); - if ((int)p2 == -1) { perror(buf2); exit(3); } + if (p2 == (u_char *)MAP_FAILED) { perror(buf2); exit(3); } close(fd2); /* If identical, we're done. */ @@ -322,7 +322,7 @@ Add(const char *dir1, const char *dir2, const char *name, struct dirent *de) if (fd1 < 0) {perror(buf2); exit (3); } fstat(fd1, &st); p1=mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd1, 0); - if ((int)p1 == -1) { perror(buf2); exit(3); } + if (p1 == (u_char *)MAP_FAILED) { perror(buf2); exit(3); } close(fd1); m2 = MD5Data(p1, st.st_size, md5_2); name_stat("CTMFM", dir2, name, de); diff --git a/usr.sbin/kvm_mkdb/nlist.c b/usr.sbin/kvm_mkdb/nlist.c index adf4a42..58d66fa 100644 --- a/usr.sbin/kvm_mkdb/nlist.c +++ b/usr.sbin/kvm_mkdb/nlist.c @@ -88,6 +88,9 @@ create_knlist(name, db) filep = (u_char*)mmap(0, sst.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (filep == (u_char*)MAP_FAILED) + err(1, "mmap failed"); + /* Read in exec structure. */ ebuf = (struct exec *) filep; diff --git a/usr.sbin/rpc.statd/file.c b/usr.sbin/rpc.statd/file.c index aeb1fc0..5dbc1cac 100644 --- a/usr.sbin/rpc.statd/file.c +++ b/usr.sbin/rpc.statd/file.c @@ -158,7 +158,7 @@ void init_file(char *filename) status_info = (FileLayout *) mmap(NULL, 0x10000000, PROT_READ | PROT_WRITE, MAP_SHARED, status_fd, 0); - if (status_info == (FileLayout *) -1) + if (status_info == (FileLayout *) MAP_FAILED) { perror("rpc.statd"); fprintf(stderr, "Unable to mmap() status file\n"); -- cgit v1.1