Mail Archives: djgpp-workers/1999/09/27/08:25:28
Hi All!
I found a very annoying bug in 2.02, I couldn't check 2.03 sorry.
The system/spawn family of functions opens the external file if it is a
.exe to check if that's a djgpp program. The bug if that chkv2prg doesn't
close the file if the test fails!
It produce a couple of nasty side effects:
1) Programs spawned by djgpp programs becomes read-only while the djgpp
program stills running (at least under W9x).
2) We leak file handlers.
Just in case it wasn't fixed I included a prototype patch, the only purpose
is just to show the points I think must be fixed.
SET
P.S. If you wonder how I found it: one user of my editor is using the editor
as Turbo Pascal 7 IDE replacement ;-)
--- chkv2prg.c~ Thu Oct 9 22:40:02 1997
+++ chkv2prg.c Sat Sep 25 14:34:38 1999
@@ -30,7 +30,10 @@
lseek(pf, 0, SEEK_SET);
if (read(pf, header, sizeof(header)) != sizeof(header))
+ {
+ close(pf);
return &type;
+ }
if (header[0] == 0x010b || header[0] == 0x014c)
{
unsigned char firstbytes[1];
@@ -64,9 +67,15 @@
coff_start += (long)header[1] - 512L;
exe_start = (unsigned long)header[4]*16L;
if (lseek(pf, exe_start, SEEK_SET) != exe_start)
+ {
+ close(pf);
return &type;
+ }
if (read(pf, go32stub, 8) != 8)
+ {
+ close(pf);
return &type;
+ }
go32stub[8] = 0;
if (strcmp(go32stub, "go32stub") == 0)
{
@@ -82,30 +91,51 @@
unsigned short coff_id;
type.version.v.major = 1;
if (lseek(pf, coff_start - 4, SEEK_SET) != coff_start-4)
+ {
+ close(pf);
return &type;
+ }
if (read(pf, &stub_offset, 4) != 4)
+ {
+ close(pf);
return &type;
+ }
if (read(pf, &coff_id, 2) != 2)
+ {
+ close(pf);
return &type;
+ }
if (coff_id == 0x010b || coff_id == 0x014c)
{
type.object_format = _V2_OBJECT_FORMAT_COFF;
type.exec_format = _V2_EXEC_FORMAT_STUBCOFF;
}
if (lseek(pf, stub_offset, 0) != stub_offset)
+ {
+ close(pf);
return &type;
+ }
if (read(pf, magic, 16) != 16)
+ {
+ close(pf);
return &type;
+ }
if (memcmp(STUB_INFO_MAGIC, magic, 16) == 0)
{
if (read(pf, &struct_length, 4) != 4)
+ {
+ close(pf);
return &type;
+ }
type.stubinfo = (_v1_stubinfo *)malloc(struct_length);
memcpy(type.stubinfo->magic, magic, 16);
type.stubinfo->struct_length = struct_length;
if (read(pf, type.stubinfo->go32, struct_length - 20)
!= struct_length - 20)
+ {
+ close(pf);
return &type;
+ }
type.has_stubinfo = 1;
}
}
--
Salvador Eduardo Tropea (SET). (Electronics Engineer)
Visit my home page: http://welcome.to/SetSoft or
http://www.geocities.com/SiliconValley/Vista/6552/
Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org
set AT ieee DOT org set-soft AT bigfoot DOT com
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013
- Raw text -