comparison src/nt.c @ 4786:6e6f7b79c1fc

xemacs: fix issue 634 -------------------- ChangeLog entries follow: -------------------- src/ChangeLog addition: 2009-11-27 Adrian Aichner <adrian@xemacs.org> * nt.c (mswindows_getdcwd): Check first whether drive is valid with _getdrives() to avoid crash in _wgetdcwd(...) when linking against msvcrt8. This fix was taken from the Mozilla project which experienced the same problem.
author Adrian Aichner <adrian@xemacs.org>
date Fri, 27 Nov 2009 00:51:41 +0100
parents 5bbff3553494
children 95c4ced5c07c
comparison
equal deleted inserted replaced
4760:217abcf015c4 4786:6e6f7b79c1fc
1813 Ibyte * 1813 Ibyte *
1814 mswindows_getdcwd (int drivelet) 1814 mswindows_getdcwd (int drivelet)
1815 { 1815 {
1816 Extbyte *cwdext; 1816 Extbyte *cwdext;
1817 Ibyte *cwd; 1817 Ibyte *cwd;
1818 1818 /* Following comment and two-liner fix comes from
1819 https://bugzilla.mozilla.org/show_bug.cgi?id=419326 which
1820 apparently fell prey to this feature of msvcrt8 as well. */
1821 /* We need to worry about IPH, for details read bug 419326.
1822 * _getdrives - http://msdn2.microsoft.com/en-us/library/xdhk0xd2.aspx
1823 * uses a bitmask, bit 0 is 'a:'
1824 * _chdrive - http://msdn2.microsoft.com/en-us/library/0d1409hb.aspx
1825 * _getdcwd - http://msdn2.microsoft.com/en-us/library/7t2zk3s4.aspx
1826 * take an int, 1 is 'a:'.
1827 *
1828 * Because of this, we need to do some math. Subtract 1 to convert from
1829 * _chdrive/_getdcwd format to _getdrives drive numbering.
1830 * Shift left x bits to convert from integer indexing to bitfield indexing.
1831 * And of course, we need to find out if the drive is in the bitmask.
1832 *
1833 * If we're really unlucky, we can still lose, but only if the user
1834 * manages to eject the drive between our call to _getdrives() and
1835 * our *calls* to _wgetdcwd.
1836 */
1837 if (!((1 << (drivelet - 1)) & _getdrives()))
1838 return NULL;
1819 if (XEUNICODE_P) 1839 if (XEUNICODE_P)
1820 cwdext = (Extbyte *) _wgetdcwd (drivelet, NULL, 0); 1840 cwdext = (Extbyte *) _wgetdcwd (drivelet, NULL, 0);
1821 else 1841 else
1822 cwdext = _getdcwd (drivelet, NULL, 0); 1842 cwdext = _getdcwd (drivelet, NULL, 0);
1823 if (cwdext == NULL) return NULL; 1843 if (cwdext == NULL) return NULL;