On Feb 10 20:16, Jeremy Drake via Cygwin-patches wrote:
> Realized an oversight (besides the messed-up subject!) after sending:
>
> > @@ -1943,14 +1961,6 @@ extern "C" FILE *
> > setmntent (const char *filep, const char *)
> > {
> > _my_tls.locals.iteration = 0;
> > - _my_tls.locals.available_drives = GetLogicalDrives ();
> > - /* Filter floppy drives on A: and B: */
> > - if ((_my_tls.locals.available_drives & 1)
> > - && get_disk_type (L"A:") == DT_FLOPPY)
> > - _my_tls.locals.available_drives &= ~1;
> > - if ((_my_tls.locals.available_drives & 2)
> > - && get_disk_type (L"B:") == DT_FLOPPY)
> > - _my_tls.locals.available_drives &= ~2;
>
> should have something like
> + if (_my_tls.locals.drivemappings)
> + {
> + delete _my_tls.locals.drivemappings;
> + _my_tls.locals.drivemappings = NULL;
> + }
> here
Careful.
Consider _my_tls.locals.drivemappings being NULL, and then a thread
running the below code, indifferent to sense or use-case:
getmntent ()
if (!_my_tls.locals.drivemappings)
_my_tls.locals.drivemappings = new dos_drive_mappings ();
--> _my_tls.locals.drivemappings = 0x12345
open ("/proc/self/mounts", O_RDONLY);
format_process_mountstuff ()
class dos_drive_mappings *drivemappings = _my_tls.locals.drivemappings;
--> drivemappings = 0x12345
setmntent ()
delete _my_tls.locals.drivemappings;
--> deletes 0x12345 !!!
_my_tls.locals.drivemappings = NULL
getmntent ()
if (!_my_tls.locals.drivemappings)
_my_tls.locals.drivemappings = new dos_drive_mappings ();
--> _my_tls.locals.drivemappings = 0x98765;
_my_tls.locals.drivemappings = drivemappings;
--> _my_tls.locals.drivemappings = 0x12345 !!!
getmntent ()
--> SIGSEGV
I think format_process_mountstuff() should not call setmntent() at all,
but just swap _my_tls.locals.drivemappings with NULL. Setting
_my_tls.locals.iteration is unnecessary as well in that case.
Compare:
/* Store old value of _my_tls.locals here. */
- int iteration = _my_tls.locals.iteration;
- unsigned available_drives = _my_tls.locals.available_drives;
- /* This reinitializes the above values in _my_tls. */
- setmntent (NULL, NULL);
- /* Restore iteration immediately since it's not used below. We use the
- local iteration variable instead*/
- _my_tls.locals.iteration = iteration;
+ class dos_drive_mappings *drivemappings = _my_tls.locals.drivemappings;
+ _my_tls.locals.drivemappings = NULL;
for (iteration = 0; (mnt = mtab->getmntent (iteration)); ++iteration)
{
with:
/* Store old value of _my_tls.locals here. */
int iteration = _my_tls.locals.iteration;
- unsigned available_drives = _my_tls.locals.available_drives;
+ class dos_drive_mappings *drivemappings = _my_tls.locals.drivemappings;
+ _my_tls.locals.drivemappings = NULL;
/* This reinitializes the above values in _my_tls. */
setmntent (NULL, NULL);
/* Restore iteration immediately since it's not used below. We use the
Thanks,
Corinna