Port-vax archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Mopd which works with ELF and a.out in Linux and can netboot ULTRIX



On Tue, 27 Oct 2020 at 17:47, Boris Gjenero <boris.gjenero%gmail.com@localhost> wrote:
>
> On 2020-10-27 1:20 p.m., David Brownlee wrote:
> >
> > I've committed the pfInit and 1k/4k changes.
> > One quick question on the mid 0 change - should the N_BADMAG (ex) &&
> > N_BADMAG (ex_swap)) check be conditionalised on mid 0?
>
> I don't think the N_BADMAG (ex) check should be conditional, because it
> seems all a.out files should have magic numbers there, which are the
> same across different operating systems. Anyways, if some foreign a.out
> files used different magic numbers, mopd couldn't tell if the file is
> OMAGIC or NMAGIC, which could cause problems. So it seems best to reject
> such files.

Ah, yes, now I actually read the code, that makes more sense :)

> BTW. I think CheckAOutFile() endian handling is wrong. Compare it:
> https://github.com/dreamlayers/netbsd-mopd/blob/c4ebe27a95731e85af7442ac53b52e8f263dc856/common/file.c#L635
> to GetAOutFileInfo():
> https://github.com/dreamlayers/netbsd-mopd/blob/c4ebe27a95731e85af7442ac53b52e8f263dc856/common/file.c#L673
>
> CheckAOutFile() lacks the mopFileSwapX((u_char *)&ex_swap, 0, 4) found
> in GetAOutFileInfo(), so ex_swap isn't actually swapped.
>
> Also, the first read() wants to get data from offset 0 in the file. But
> it doesn't seek to offset 0 and the file has been read before. In
> GetFileInfo() it runs after CheckElfFile(), which reads stuff and
> doesn't seek to the start of the file afterwards. So ex gets read from
> wrong position in the file.
>
> These things interact to make things work on little endian, where
> ex_swap gets accepted instead of ex. There is a seek to the start of the
> file before ex_swap is read, and ex_swap doesn't get swapped. But it
> should fail on big endian. I've been meaning to fix this but don't have
> a big endian build environment set up yet.

Ah... code which has obviously been cut & pasted and then adjusted over time.

Both methods are... interesting. In addition to missed seeks it reads
it twice to get the swapped struct exec rather than just memcpy the
first copy. It swaps ex_swap, then tests ex and if it fails tests
swap_ex and then swaps ex. Aaaaaaaaa.

I wonder what a simple cleanup pass might end up with

https://github.com/abs0/netbsd-mopd/commit/6ab8555817f3dff23c506464d302d1a40bca6214

(In case you want to merge it back in)

David


Home | Main Index | Thread Index | Old Index