After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 150007 - file chooser crashes if g_get_home_dir() returns NULL
file chooser crashes if g_get_home_dir() returns NULL
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkFileChooser
2.4.x
Other All
: Normal critical
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-08-12 23:46 UTC by David Breeding
Modified: 2011-02-04 16:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Suggested patch (4.44 KB, patch)
2004-08-14 03:30 UTC, Tor Lillqvist
none Details | Review

Description David Breeding 2004-08-12 23:46:21 UTC
Windows system is Win98.  Currently using Tor Lillqvist's GTK packages,
compiling with MinGW/msys, using gcc.  When the program is called from
the DOS window (the "DOS PROMPT", the program will segfault.  I get four
lines of errors relating to the path, and the filename, stating that the test
"..filename != NULL.." failed.  If this same program is called under msys, it
seems to operate correctly.  The same source compiled and run under Linux
apparently works well.

This program will crash on my system:
--------------- cut ----------------------
#include <gtk/gtk.h>

int main(int argc, char * argv[])
{
    GtkWidget *window;
    GtkWidget *dialog;
    
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "destroy",
                     G_CALLBACK(gtk_main_quit), NULL);

    dialog = gtk_file_chooser_dialog_new("File Chooser dialog",
                                         GTK_WINDOW(window),
                                         GTK_FILE_CHOOSER_ACTION_OPEN,
                                         GTK_STOCK_CANCEL,
                                         GTK_RESPONSE_CANCEL,
                                         GTK_STOCK_OPEN,
                                         GTK_RESPONSE_ACCEPT,
                                         NULL);
    gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),"");
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
}
------------------------- cut --------------------------
Comment 1 David Breeding 2004-08-13 16:45:28 UTC
I've located the problem.  In my DOS window, I didn't have the HOME variable
set.  When gtk_file_chooser failed to find this variable, it left the pointer
NULL, which, of course, caused a segfault.

This is not, in fact, a win32-specific bug.  I tried it under msys after
unsetting HOME and got the same crash.  Didn't try it under Linux, but am
convinced that the same would occur.

It seems that in a case like this, although I suppose the omission of a HOME
variable is a user error, the function should notify the user of the need via a
Message box or the like.  Perhaps a default could be assigned if HOME is undefined?
Comment 2 John Ehresman 2004-08-13 17:08:49 UTC
Do you have IE 5+ installed?  gtk should work without it (I think the current
policy is to support back to win95), but it would explain why no home dir is
returned.  The issue is the code to set g_home_dir in g_get_any_init() in
gutils.c, which probably sets g_home_dir to NULL if none of the environment
variables ar set.

Should g_home_dir be set to c:\ if nothing else can be found?  This would affect
mainly older (95, 98, NT4) systems.  We could also add direct api calls to get
the info in case the environment is missing some of the values.
Comment 3 Tor Lillqvist 2004-08-14 02:37:46 UTC
Regardless whether g_get_home_dir() always should return something on Windows, 
the fact is that it can return NULL, even on Unix. (And probably will stay that 
way on Unix, better to return NULL that start guessing. Single-user Windows 
machines are another thing, there you probably won't cause any security risks 
etc if you pretend %SYSTEMDRIVE%:\ is HOME.) gtkfilechooserdefault.c, for 
instance, doesn't take this into account. Will attach patch shortly.

See bug #105887 for improving g_get_home_dir() on Windows, to return NULL less 
often.
Comment 4 Tor Lillqvist 2004-08-14 03:30:25 UTC
Created attachment 30534 [details] [review]
Suggested patch
Comment 5 Tor Lillqvist 2004-08-14 16:47:55 UTC
Patch applied to gtk-2-4 and HEAD.