Fix a possible crash in the file browser
authorByrial Jensen <byrial@vip.cybercity.dk>
Sun, 18 Dec 2011 12:26:20 +0000 (13:26 +0100)
committerByrial Jensen <byrial@vip.cybercity.dk>
Sun, 18 Dec 2011 12:26:20 +0000 (13:26 +0100)
If the OK button was selected in the file browser when no file was selected
there was a read out of bounds which could crash xboard

filebrowser/selfile.c

index e6edfe4..729453b 100644 (file)
@@ -883,7 +883,7 @@ XsraSelFile(toplevel, prompt, ok, cancel, failed,
                                SFprepareToReturn();
                                return stderr;
                        }
-                       if ((*name_return)[strlen(*name_return)-1] != '/' &&         // [HGM] refuse directories
+                       if ((!(*name_return)[0] || (*name_return)[strlen(*name_return)-1] != '/') &&      // [HGM] refuse directories
                            (fp = SFopenFile(*name_return, mode, prompt, failed))) {
                                SFprepareToReturn();
                                return fp;