diff options
author | H. Peter Anvin <hpa@zytor.com> | 2001-10-09 06:47:03 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2001-10-09 06:47:03 +0000 |
commit | d20f1d7701fae2cf2f0c4ae7720fea6bd302d415 (patch) | |
tree | ae04f9e61d3b6d56220f4deb0b6f766ced403440 | |
parent | a5c4ef9ffa36590b5786e2983a95309a49b69bc3 (diff) | |
download | lpsm-d20f1d7701fae2cf2f0c4ae7720fea6bd302d415.tar.gz lpsm-d20f1d7701fae2cf2f0c4ae7720fea6bd302d415.tar.xz lpsm-d20f1d7701fae2cf2f0c4ae7720fea6bd302d415.zip |
Create a Makefile; fix memory-overwrite bug when file_len > requested_len
-rw-r--r-- | Makefile | 45 | ||||
-rw-r--r-- | arena.c | 21 | ||||
-rw-r--r-- | system.h | 2 |
3 files changed, 57 insertions, 11 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a44be9f --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +TEST = teststore test_mmap ftrunctest +SONAME = libobjstore.so.0 +VERSION = 0.0.1 +OBJSTORE = libobjstore.so libobjstore.a + +OSOBJ = objstore.o +OSPICOBJ = $(patsubst %.o,%.pic.o,$(OSOBJ)) + +CC = gcc +CFLAGS = -O2 -g +PICFLAGS = $(CFLAGS) -fPIC +SOFLAGS = -shared + +AR = ar cq +RANLIB = ranlib + +all: $(OBJSTORE) $(TEST) + +clean: + rm -f *.o *~ core $(OBJSTORE) $(TEST) + +%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $< + +%.pic.o: %.c + $(CC) $(PICFLAGS) -o $@ -c $< + +libobjstore.so: $(OSPICOBJ) + $(CC) $(SOFLAGS) -Wl,-soname,$(SONAME) -o libobjstore.so.$(VERSION) $(OSPICOBJ) + ln -sf libobjstore.so.$(VERSION) $(SONAME) + ln -sf libobjstore.so.$(VERSION) libobjstore.so + +libobjstore.a: $(OSOBJ) + rm -f libobjstore.a + $(AR) libobjstore.a $(OSOBJ) + $(RANLIB) libobjstore.a + +teststore: teststore.o libobjstore.a + $(CC) $(LDFLAGS) -o $@ $< libobjstore.a + +test_mmap: test_mmap.o + $(CC) $(LDFLAGS) -o $@ $< + +ftrunctest: ftrunctest.o + $(CC) $(LDFLAGS) -o $@ $< @@ -105,7 +105,7 @@ static void objstore_sigsegv(int signal, siginfo_t *siginfo, void *ptr) { struct ObjStore *os = objstore_os_struct; void *page; - off_t offset; + uintptr_t npage, offset; char *pageinfo; struct flock lock; int old_errno = errno; @@ -127,23 +127,24 @@ static void objstore_sigsegv(int signal, siginfo_t *siginfo, void *ptr) # endif /* __i386__ */ #endif /* __linux__ */ + page = (void *)((uintptr_t)siginfo->si_addr & ~(os->pagesize-1)); + offset = (uintptr_t)page - (uintptr_t)os->arena; + npage = (offset >> os->pageshift); + pageinfo = os->pageinfo + npage; + if ( signal != SIGSEGV || siginfo->si_code != SEGV_ACCERR || - ((uintptr_t)siginfo->si_addr - (uintptr_t)os->arena) >= os->arena_len ) { + offset >= os->arena_len ) { struct sigaction dfl; - + dfl.sa_handler = SIG_DFL; sigemptyset(&dfl.sa_mask); dfl.sa_flags = SA_ONESHOT; sigaction(SIGSEGV, &dfl, NULL); - + errno = old_errno; return; /* Re-take fault */ } - - page = (void *)((uintptr_t)siginfo->si_addr & ~(os->pagesize-1)); - offset = (uintptr_t)page - (uintptr_t)os->arena; - pageinfo = os->pageinfo + (offset >> os->pageshift); - + mprotect(page, os->pagesize, PROT_READ|PROT_WRITE); switch ( (enum page_status) *pageinfo ) { @@ -350,7 +351,7 @@ void *objstore_init(char *main_file, char *log_file, size_t *arena_len) lock.l_len = 0; while ( fcntl(os->main_fd, F_SETLKW, &lock) == -1 && errno == EINTR ); file_len = lseek(os->main_fd, 0, SEEK_END); - if ( len == 0 ) { + if ( len < file_len ) { len = file_len; } len = (len + os->pagesize - 1) & ~(os->pagesize - 1); @@ -23,7 +23,7 @@ /* These constants are appropriate for Linux/i386 */ /* This is where we map the database file - must be constant */ -#define ARENA_ADDRESS ((void *)0x60000000) +#define ARENA_ADDRESS ((void *)0x60000000UL) #endif /* SYSTEM_H */ |