Edit read a file into a buffer it never checked the size of
Opening hello.asm showed a thirty one line file as three, one of them cut short. Opening it again hung the machine: the emulator kept running and nothing ever answered. Entry is the buffer a line is read into, and it is followed in memory by TextHead and ArenaFree - the head of the document, and the pointer its line allocator hands out. The loop that splits a file into lines copied characters in WITH NO BOUND AT ALL, so a 94 character line wrote thirteen bytes over both of them. The list head then pointed into the middle of the text and the allocator handed out an address inside the file, which is why the second open walked a list that led back into itself for ever. Typing was always safe. osReadLine is told how much room there is, so a new document behaved perfectly and a source file did not - which is exactly how the user found it, and why it looked like a mystery rather than a bug. The bound is there now, and the buffer is 128 characters: what a line is everywhere else on this machine, the same number configuration files use, rather than a second answer to a question already answered. hello.asm fits. A file with a longer line is REFUSED rather than shortened. This is an editor - a line cut on the way in would be written back cut, and the file damaged by having been looked at. It says so and exits with a status of one, which it can do since this afternoon; the file is byte identical afterwards, and the test checks that. Opened twice in the test, because once is not enough to see it: the first open does the damage and the second is what never returns. This is the third time this shape has turned up: a buffer written past its end into the variables that happened to follow it. The prompt walked off CwdText into the shell's own command names; the assembler's output ran into its label table. Every one was found by a person using the machine.
This commit is contained in:
@@ -2,7 +2,8 @@ Programs/Boot/slotData.asm redundant-setd 1
|
||||
Programs/Boot/stage1.asm redundant-setd 2
|
||||
Programs/Boot/stage2.asm redundant-setd 1
|
||||
Programs/CosmOS/Apps/Copy.asm redundant-setd 2
|
||||
Programs/CosmOS/Apps/Edit.asm redundant-setd 3
|
||||
Programs/CosmOS/Apps/Edit.asm redundant-assignment 1
|
||||
Programs/CosmOS/Apps/Edit.asm redundant-setd 4
|
||||
Programs/CosmOS/Apps/Status.asm redundant-setd 1
|
||||
Programs/CosmOS/Apps/Wander.asm redundant-setd 1
|
||||
Programs/CosmOS/Assembler/Asm.asm redundant-assignment 2
|
||||
|
||||
Reference in New Issue
Block a user