diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2015-01-31 12:09:24 +0000 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2015-01-31 12:09:24 +0000 |
| commit | 22b4288c23da68338be7a270ffe4ec802c27233e (patch) | |
| tree | 6799ba06ebfd32e5bbc293fed06b8fd741a3c077 /src | |
| parent | b7be893f38ed2ca151802a192d4876b4a122bd9e (diff) | |
Fix potential buffer overflow (Windows: BEX64 error) and home dir (STR 3166).
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10544 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_File_Chooser2.cxx | 42 | ||||
| -rw-r--r-- | src/Fl_Preferences.cxx | 2 |
2 files changed, 34 insertions, 10 deletions
diff --git a/src/Fl_File_Chooser2.cxx b/src/Fl_File_Chooser2.cxx index bddae82f2..84a17beb0 100644 --- a/src/Fl_File_Chooser2.cxx +++ b/src/Fl_File_Chooser2.cxx @@ -410,6 +410,8 @@ static int compare_dirnames(const char *a, const char *b); static void quote_pathname(char *, const char *, int); static void unquote_pathname(char *, const char *, int); +// use platform dependent getenv() to get the home directory (STR #3166) +static const char* get_homedir(); // // 'Fl_File_Chooser::count()' - Return the number of selected files. @@ -539,7 +541,7 @@ Fl_File_Chooser::favoritesButtonCB() if (!v) { // Add current directory to favorites... - if (getenv("HOME")) v = favoritesButton->size() - 5; + if (get_homedir()) v = favoritesButton->size() - 5; else v = favoritesButton->size() - 4; sprintf(menuname, "favorite%02d", v); @@ -1273,8 +1275,8 @@ Fl_File_Chooser::update_favorites() favoritesButton->add(add_favorites_label, FL_ALT + 'a', 0); favoritesButton->add(manage_favorites_label, FL_ALT + 'm', 0, 0, FL_MENU_DIVIDER); favoritesButton->add(filesystems_label, FL_ALT + 'f', 0); - - if ((home = getenv("HOME")) != NULL) { + + if ((home = get_homedir()) != NULL) { quote_pathname(menuname, home, sizeof(menuname)); favoritesButton->add(menuname, FL_ALT + 'h', 0); } @@ -1665,18 +1667,22 @@ quote_pathname(char *dst, // O - Destination string const char *src, // I - Source string int dstsize) // I - Size of destination string { - dstsize --; + dstsize--; // prepare for trailing zero while (*src && dstsize > 1) { if (*src == '\\') { // Convert backslash to forward slash... *dst++ = '\\'; *dst++ = '/'; + dstsize -= 2; src ++; } else { - if (*src == '/') *dst++ = '\\'; - + if (*src == '/') { + *dst++ = '\\'; + dstsize--; + } *dst++ = *src++; + dstsize--; } } @@ -1693,16 +1699,34 @@ unquote_pathname(char *dst, // O - Destination string const char *src, // I - Source string int dstsize) // I - Size of destination string { - dstsize --; + dstsize--; // prepare for trailing zero - while (*src && dstsize > 1) { - if (*src == '\\') src ++; + while (*src && dstsize > 0) { + if (*src == '\\') src++; *dst++ = *src++; + dstsize--; } *dst = '\0'; } +// +// 'get_homedir()' - Try to find the home directory (platform dependent). + +static const char* +get_homedir() { + + const char *home = fl_getenv("HOME"); + +#ifdef WIN32 + + if (!home) home = fl_getenv("UserProfile"); + +#endif // WIN32 + + return home; +} + // // End of "$Id$". diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx index 6f4d0cece..6bda342e4 100644 --- a/src/Fl_Preferences.cxx +++ b/src/Fl_Preferences.cxx @@ -679,7 +679,7 @@ char Fl_Preferences::get( const char *key, char *text, const char *defaultValue, } if ( !v ) v = defaultValue; if ( v ) strlcpy(text, v, maxSize); - else text = 0; + else *text = 0; return ( v != defaultValue ); } |
