Re: [PATCH] A new version of the sys_swapon bugfix

Andreas Schwab (schwab@issan.informatik.uni-dortmund.de)
03 Nov 1998 14:43:33 +0100


Jakub Jelinek <jj@sunsite.ms.mff.cuni.cz> writes:

|> >
|> > Jakub Jelinek <jj@sunsite.ms.mff.cuni.cz> writes:
|> >
|> > |> Hi!
|> > |>
|> > |> This is a new enhanced version of the sys_swapon bugfix.
|> > |> I've checked C standard and I cannot find any word about pointer + integer
|> > |> being promoted first to pointer + long,
|> >
|> > Pointer arithmetics is clearly defined, and you can add any integer type
|> > to a pointer, independent of the size of the pointer or integer.
|>
|> I just made a typo in the comment above the code, it should really be
|> unsigned int i = 0;
|>
|> which is the case in swapfile.c, where swap_header->info.nr_badpages is
|> unsigned int, thus if it is 0 and we subtract 1, it will result into
|> 0xffffffff and &swap_header->info.badpages[0xffffffff] is really wrong on
|> 64bit archs, so the patch is IMHO correct.

Better change

(void *) &swap_header->info.badpages[swap_header->info.nr_badpages-1] >= (void *) swap_header->magic.magic

into

(void *) &swap_header->info.badpages[swap_header->info.nr_badpages] > (void *) swap_header->magic.magic

which avoids the whole problem.

Andreas.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/