Article View: comp.os.os2.programmer
Article #1231Findfirst in DOS box can crash OS/2
From: Mark Alexander
Date: Fri, 28 Aug 1992 19:41
Date: Fri, 28 Aug 1992 19:41
30 lines
1295 bytes
1295 bytes
Using the 'findfirst' system call in a DOS program can crash OS/2 2.0
6.307 if the filename argument is very close to the end of the stack
segment. In my test program, the filename being searched for was
"blorch", and was stored at SS:FFF6. This can happen if you are using
Borland C++, and the filename is passed on the command line.
The workaround is to use strdup() to make a copy of the filename in
a "safer" location.
Here is the test program. I compiled it with BC++ 3.1 using small model.
#include <stdio.h>
#include <dir.h>
int main(int argc, char *argv[])
{
struct ffblk ffile;
if (argc != 2)
{
printf("You must supply one argument.\n");
return 1;
}
if (findfirst(argv[1],&ffile,0x3f) != 0)
printf("Unable to find %s\n", argv[1]);
else
printf("Found %s\n", argv[1]);
return 0;
}
Technical Details
Message-ID:
<1992Aug28.194103.5195@genghis.borland.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!olivea!decwrl!borland.com!alexandeShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!decwrl!borland.com!alexande From: alexande@genghis.borland.com (Mark Alexander) Newsgroups: comp.os.os2.programmer Subject: Findfirst in DOS box can crash OS/2 Message-ID: <1992Aug28.194103.5195@genghis.borland.com> Date: 28 Aug 92 19:41:03 GMT Sender: news@borland.com (News Admin) Organization: Borland International Lines: 30 Originator: alexande@genghis.borland.com