Skip to content

Commit a219d09

Browse files
committed
Fix msync calls beyond the end of the mapping
Fixed very infrequent errors of page alignment in msync calls. Thanks to Chris Knipe for the bug report and to Richard Kettlewell for the patch. close #327
1 parent 64f1e1a commit a219d09

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

CONTRIBUTORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,5 @@ Tim Fardell, Remco Rijnders, David Binderman, Tony Evans, Christian Garbs,
279279
Jesse Rehmer, Colin Watson, Lauri Tirkkonen, Christian Mock, Marcus Jodorf,
280280
Richard Kettlewell, Yuriy M. Kaminskiy, Bill Parker, Thomas Hochstein,
281281
Tanguy Ortolo, Michael Baeuerle, Kevin Bowling, Andreas Kempe, Hauke Lampe,
282-
Enrik Berkhan, Nigel Reed, Christian Clauss, Roberto Corrado, Roman Donchenko
282+
Enrik Berkhan, Nigel Reed, Christian Clauss, Roberto Corrado, Roman Donchenko,
283+
Chris Knipe

doc/pod/news.pod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ to Roman Donchenko for the code simplification and cleaning.
3535

3636
=item *
3737

38+
Fixed very infrequent errors of memory mapping when updating the F<active>
39+
file or using the tradindexed overview method, as well as when updating the
40+
F<history> file with I<nfswriter> set to true. Thanks to Chris Knipe for the
41+
bug report and to Richard Kettlewell for the patch.
42+
43+
=item *
44+
3845
Fixed the rotation of the F<perl-nocem.log> file generated when syslog is not
3946
available or the B<-l> flag used with B<perl-nocem>: the contents of this log
4047
file was mistakenly appended to F<news.notice> by B<scanlogs>.

frontends/cnfsstat.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ sub get_cycbuff_info {
615615
my $pagesize = 16384;
616616
my $minartoffset = int($len / ($blksz * 8)) + 512;
617617
# Align upwards:
618-
$minartoffset = ($minartoffset + $pagesize) & ~($pagesize - 1);
618+
$minartoffset = ($minartoffset + $pagesize - 1) & ~($pagesize - 1);
619619

620620
if ($cyclenum == 0 && $free == $minartoffset) {
621621
# The cycbuff has no articles yet.

lib/mmap.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/*
22
** Manipulation routines for memory-mapped pages.
33
**
4-
** Written by Alex Kiernan (alex.kiernan@thus.net)
4+
** Written by Alex Kiernan <alex.kiernan@thus.net> in 2002.
5+
**
6+
** Various bug fixes, code and documentation improvements
7+
** in 2002-2004, 2007, 2021-2023, 2025.
58
*/
69

710
#include "portable/system.h"
@@ -27,7 +30,7 @@ inn__msync_page(void *p, size_t length, int flags)
2730
} else {
2831
const size_t mask = ~(size_t) (pagesize - 1);
2932
char *start = (char *) ((uintptr_t) p & mask);
30-
char *end = (char *) (((uintptr_t) p + length + pagesize) & mask);
33+
char *end = (char *) (((uintptr_t) p + length + pagesize - 1) & mask);
3134

3235
return msync(start, end - start, flags);
3336
}

storage/cnfs/cnfs.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,8 @@ CNFSinit_disks(CYCBUFF *cycbuff)
760760
/*
761761
** The minimum article offset will be the size of the bitfield itself,
762762
** len / (blocksize * 8), plus however many additional blocks the
763-
*CYCBUFF
764-
** external header occupies ... then round up to the next block.
763+
** *CYCBUFF external header occupies... then round up to the next
764+
** block.
765765
*/
766766
minartoffset = cycbuff->len / (cycbuff->blksz * 8) + CNFS_BEFOREBITF;
767767
tonextblock =
@@ -1002,11 +1002,10 @@ CNFSread_config(void)
10021002
static void
10031003
cnfs_mapcntl(void *p, size_t length, int flags)
10041004
{
1005-
char *start, *end;
1005+
const size_t mask = ~(size_t) (pagesize - 1);
1006+
char *start = (char *) ((uintptr_t) p & mask);
1007+
char *end = (char *) (((uintptr_t) p + length + pagesize - 1) & mask);
10061008

1007-
start = (char *) ((uintptr_t) p & ~(size_t) (pagesize - 1));
1008-
end = (char *) (((uintptr_t) p + length + pagesize)
1009-
& ~(size_t) (pagesize - 1));
10101009
if (flags == MS_INVALIDATE) {
10111010
msync(start, end - start, flags);
10121011
} else {

0 commit comments

Comments
 (0)