[haiku-commits] haiku: hrev46926 - src/kits/screensaver src/preferences/screensaver headers/private/screen_saver

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 25 Feb 2014 21:04:18 +0100 (CET)

hrev46926 adds 9 changesets to branch 'master'
old head: 8b804bc17b2fe8e85fbdca88c0f8c27bed3648a2
new head: e9a0833a86246dde90eef56e09b36fc4069a5ee4
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=e9a0833+%5E8b804bc

----------------------------------------------------------------------------

a3dc72e: ScreenSaverSettings: Silly indentiation fix

6d55c2c: ScreenSaver: check function return values for success

4116ae4: ScreenSaverSettings: check find_directory return value

d960838: ScreenSaverRunner: clarify some comments

84466ce: ScreenSaverRunner: check return value of methods

06f133c: ScreenSaverRunner: treat load_add_on return value like an image_id
  
  ... rather than a status_t, because that's what it is.

94f8ac8: ScreenSaverRunner: print errors to stderr instead of stdout.
  
  Also print on a couple of new error cases:
  * print and error if fSaver is NULL,
  * print and error if unload_add_on failed.

9d312ae: ScreenSaverSettings: Check that name is valid
  
  ... before trying to use it in GetModuleState() and SetModuleState()
  
  also, rename the stateMsg variable to stateMessage (already correct in header)

e9a0833: ScreenSaverRunner: Fix segmentation fault loading bad screen saver.
  
  When Settings.ModuleName() returned NULL here we got a segmentation fault
  trying to access the pointer.
  
  I ran into this trying to load up a non-screensaver executable in ScreenSaver,
  it crashed instead of doing the right thing and refusing to load.
  
  Also, since we go to the trouble of saving this to a variable, we should 
actually use it.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 49 insertions(+), 33 deletions(-)
.../private/screen_saver/ScreenSaverSettings.h   |  4 +-
src/kits/screensaver/ScreenSaverRunner.cpp       | 41 ++++++++++++--------
src/kits/screensaver/ScreenSaverSettings.cpp     | 26 ++++++++-----
.../screensaver/ScreenSaverWindow.cpp            | 11 ++++--

############################################################################

Commit:      a3dc72e69c1f71559c4eb308d543c3e8c0ea8c70
URL:         http://cgit.haiku-os.org/haiku/commit/?id=a3dc72e
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 18:27:53 2014 UTC

ScreenSaverSettings: Silly indentiation fix

----------------------------------------------------------------------------

diff --git a/headers/private/screen_saver/ScreenSaverSettings.h 
b/headers/private/screen_saver/ScreenSaverSettings.h
index 15299d1..78257cc 100644
--- a/headers/private/screen_saver/ScreenSaverSettings.h
+++ b/headers/private/screen_saver/ScreenSaverSettings.h
@@ -50,8 +50,8 @@ public:
                        bigtime_t               SuspendTime() const { return 
fSuspendTime; }
                        bigtime_t               OffTime() const { return 
fOffTime; }
 
-                       screen_corner           BlankCorner() const { return 
fBlankCorner; }
-                       screen_corner           NeverBlankCorner() const { 
return fNeverBlankCorner; }
+                       screen_corner   BlankCorner() const { return 
fBlankCorner; }
+                       screen_corner   NeverBlankCorner() const { return 
fNeverBlankCorner; }
                        bool                    LockEnable() const { return 
fLockEnabled; }
                        bigtime_t               PasswordTime() const { return 
fPasswordTime; }
                        const char*             Password() { return 
fPassword.String(); }

############################################################################

Commit:      6d55c2c490ef3c00b18548fbafbdc534a721e8e6
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6d55c2c
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 18:35:08 2014 UTC

ScreenSaver: check function return values for success

----------------------------------------------------------------------------

diff --git a/src/preferences/screensaver/ScreenSaverWindow.cpp 
b/src/preferences/screensaver/ScreenSaverWindow.cpp
index 58cbb45..b17cb24 100644
--- a/src/preferences/screensaver/ScreenSaverWindow.cpp
+++ b/src/preferences/screensaver/ScreenSaverWindow.cpp
@@ -702,8 +702,10 @@ ModulesView::PopulateScreenSaverList()
 
        for (uint32 i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
                BPath basePath;
-               find_directory(which[i], &basePath);
-               basePath.Append("Screen Savers", true);
+               if (find_directory(which[i], &basePath) != B_OK)
+                       continue;
+               else if (basePath.Append("Screen Savers", true) != B_OK)
+                       continue;
 
                BDirectory dir(basePath.Path());
                BEntry entry;
@@ -712,8 +714,9 @@ ModulesView::PopulateScreenSaverList()
                        if (entry.GetName(name) != B_OK)
                                continue;
 
-                       BPath path = basePath;
-                       path.Append(name);
+                       BPath path(basePath);
+                       if (path.Append(name) != B_OK)
+                               continue;
 
                        ScreenSaverItem* item = new ScreenSaverItem(name, 
path.Path());
                        fScreenSaversListView->AddItem(item);

############################################################################

Commit:      4116ae4ffd4a40073ab5030b74a89d091041c011
URL:         http://cgit.haiku-os.org/haiku/commit/?id=4116ae4
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 19:09:47 2014 UTC

ScreenSaverSettings: check find_directory return value

----------------------------------------------------------------------------

diff --git a/src/kits/screensaver/ScreenSaverSettings.cpp 
b/src/kits/screensaver/ScreenSaverSettings.cpp
index 2d667fa..0209f60 100644
--- a/src/kits/screensaver/ScreenSaverSettings.cpp
+++ b/src/kits/screensaver/ScreenSaverSettings.cpp
@@ -27,10 +27,10 @@
 ScreenSaverSettings::ScreenSaverSettings()
 {
        BPath path;
-       find_directory(B_USER_SETTINGS_DIRECTORY, &path);
-
-       fSettingsPath = path;
-       fSettingsPath.Append("ScreenSaver_settings", true);
+       if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
+               fSettingsPath = path;
+               fSettingsPath.Append("ScreenSaver_settings", true);
+       }
 
        Defaults();
 }

############################################################################

Commit:      d960838b5b81641f82b2b6da10606113d542731d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d960838
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 19:32:43 2014 UTC

ScreenSaverRunner: clarify some comments

----------------------------------------------------------------------------

diff --git a/src/kits/screensaver/ScreenSaverRunner.cpp 
b/src/kits/screensaver/ScreenSaverRunner.cpp
index 024c28e..66b58fb 100644
--- a/src/kits/screensaver/ScreenSaverRunner.cpp
+++ b/src/kits/screensaver/ScreenSaverRunner.cpp
@@ -103,7 +103,7 @@ ScreenSaverRunner::_LoadAddOn()
 
        BScreenSaver* (*instantiate)(BMessage*, image_id);
 
-       // try all directories until the first one succeeds
+       // try each directory until one succeeds
 
        directory_which which[] = {
                B_USER_NONPACKAGED_ADDONS_DIRECTORY,
@@ -129,7 +129,8 @@ ScreenSaverRunner::_LoadAddOn()
                printf("Unable to open add-on: %s: %s\n", path.Path(),
                        strerror(fAddonImage));
        } else {
-               // Look for the one C function that should exist.
+               // look for the one C function that should exist,
+               // instantiate_screen_saver()
                if (get_image_symbol(fAddonImage, "instantiate_screen_saver",
                                B_SYMBOL_TYPE_TEXT, (void **)&instantiate) != 
B_OK) {
                        printf("Unable to find the instantiator\n");

############################################################################

Commit:      84466cefd3ea62b7a18aa30002a6cfc362b3d9ba
URL:         http://cgit.haiku-os.org/haiku/commit/?id=84466ce
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 19:34:04 2014 UTC

ScreenSaverRunner: check return value of methods

----------------------------------------------------------------------------

diff --git a/src/kits/screensaver/ScreenSaverRunner.cpp 
b/src/kits/screensaver/ScreenSaverRunner.cpp
index 66b58fb..d535ac5 100644
--- a/src/kits/screensaver/ScreenSaverRunner.cpp
+++ b/src/kits/screensaver/ScreenSaverRunner.cpp
@@ -116,9 +116,10 @@ ScreenSaverRunner::_LoadAddOn()
        for (uint32 i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
                if (find_directory(which[i], &path, false) != B_OK)
                        continue;
-
-               path.Append("Screen Savers");
-               path.Append(fSettings.ModuleName());
+               else if (path.Append("Screen Savers") != B_OK)
+                       continue;
+               else if (path.Append(fSettings.ModuleName()) != B_OK)
+                       continue;
 
                fAddonImage = load_add_on(path.Path());
                if (fAddonImage >= B_OK)

############################################################################

Commit:      06f133c1f2b16a3fffd00fe5a9a64cbfdbb55ab3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=06f133c
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 19:42:34 2014 UTC

ScreenSaverRunner: treat load_add_on return value like an image_id

... rather than a status_t, because that's what it is.

----------------------------------------------------------------------------

diff --git a/src/kits/screensaver/ScreenSaverRunner.cpp 
b/src/kits/screensaver/ScreenSaverRunner.cpp
index d535ac5..407881a 100644
--- a/src/kits/screensaver/ScreenSaverRunner.cpp
+++ b/src/kits/screensaver/ScreenSaverRunner.cpp
@@ -122,14 +122,11 @@ ScreenSaverRunner::_LoadAddOn()
                        continue;
 
                fAddonImage = load_add_on(path.Path());
-               if (fAddonImage >= B_OK)
+               if (fAddonImage > 0)
                        break;
        }
 
-       if (fAddonImage < B_OK) {
-               printf("Unable to open add-on: %s: %s\n", path.Path(),
-                       strerror(fAddonImage));
-       } else {
+       if (fAddonImage > 0) {
                // look for the one C function that should exist,
                // instantiate_screen_saver()
                if (get_image_symbol(fAddonImage, "instantiate_screen_saver",
@@ -146,7 +143,8 @@ ScreenSaverRunner::_LoadAddOn()
                                strerror(fSaver->InitCheck()));
                        _CleanUp();
                }
-       }
+       } else
+               printf("Unable to open add-on %s.\n", path.Path());
 
        Resume();
 }

############################################################################

Commit:      94f8ac8cf1e63d9290981d8430bdf2e0c93017d0
URL:         http://cgit.haiku-os.org/haiku/commit/?id=94f8ac8
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 19:45:54 2014 UTC

ScreenSaverRunner: print errors to stderr instead of stdout.

Also print on a couple of new error cases:
* print and error if fSaver is NULL,
* print and error if unload_add_on failed.

----------------------------------------------------------------------------

diff --git a/src/kits/screensaver/ScreenSaverRunner.cpp 
b/src/kits/screensaver/ScreenSaverRunner.cpp
index 407881a..c651286 100644
--- a/src/kits/screensaver/ScreenSaverRunner.cpp
+++ b/src/kits/screensaver/ScreenSaverRunner.cpp
@@ -131,20 +131,23 @@ ScreenSaverRunner::_LoadAddOn()
                // instantiate_screen_saver()
                if (get_image_symbol(fAddonImage, "instantiate_screen_saver",
                                B_SYMBOL_TYPE_TEXT, (void **)&instantiate) != 
B_OK) {
-                       printf("Unable to find the instantiator\n");
+                       fprintf(stderr, "Unable to find the instantiation 
function.\n");
                } else {
                        BMessage state;
                        fSettings.GetModuleState(fSettings.ModuleName(), 
&state);
                        fSaver = instantiate(&state, fAddonImage);
                }
 
-               if (fSaver->InitCheck() != B_OK) {
-                       printf("ScreenSaver initialization failed: %s!\n",
+               if (fSaver == NULL) {
+                       fprintf(stderr, "Screen saver initialization 
failed.\n");
+                       _CleanUp();
+               } else if (fSaver->InitCheck() != B_OK) {
+                       fprintf(stderr, "Screen saver initialization failed: 
%s.\n",
                                strerror(fSaver->InitCheck()));
                        _CleanUp();
                }
        } else
-               printf("Unable to open add-on %s.\n", path.Path());
+               fprintf(stderr, "Unable to open add-on %s.\n", path.Path());
 
        Resume();
 }
@@ -157,7 +160,11 @@ ScreenSaverRunner::_CleanUp()
        fSaver = NULL;
 
        if (fAddonImage >= 0) {
-               unload_add_on(fAddonImage);
+               status_t result = unload_add_on(fAddonImage);
+               if (result != B_OK) {
+                       fprintf(stderr, "Unable to unload screen saver add-on: 
%s.\n",
+                               strerror(result));
+               }
                fAddonImage = -1;
        }
 }

############################################################################

Commit:      9d312ae7509b6d47dbbae89e3d55dcf4cbba7b0d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=9d312ae
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 19:47:53 2014 UTC

ScreenSaverSettings: Check that name is valid

... before trying to use it in GetModuleState() and SetModuleState()

also, rename the stateMsg variable to stateMessage (already correct in header)

----------------------------------------------------------------------------

diff --git a/src/kits/screensaver/ScreenSaverSettings.cpp 
b/src/kits/screensaver/ScreenSaverSettings.cpp
index 0209f60..73175cd 100644
--- a/src/kits/screensaver/ScreenSaverSettings.cpp
+++ b/src/kits/screensaver/ScreenSaverSettings.cpp
@@ -172,21 +172,27 @@ ScreenSaverSettings::Message()
 
 
 status_t
-ScreenSaverSettings::GetModuleState(const char* name, BMessage* stateMsg)
+ScreenSaverSettings::GetModuleState(const char* name, BMessage* stateMessage)
 {
+       if (name == NULL || *name == '\0')
+               return B_BAD_VALUE;
+
        BString stateName("modulesettings_");
-       stateName += name;
-       return fSettings.FindMessage(stateName.String(), stateMsg);
+       stateName << name;
+       return fSettings.FindMessage(stateName, stateMessage);
 }
 
 
 void
-ScreenSaverSettings::SetModuleState(const char* name, BMessage* stateMsg)
+ScreenSaverSettings::SetModuleState(const char* name, BMessage* stateMessage)
 {
+       if (name == NULL || *name == '\0')
+               return;
+
        BString stateName("modulesettings_");
-       stateName += name;
+       stateName << name;
        fSettings.RemoveName(stateName.String());
-       fSettings.AddMessage(stateName.String(), stateMsg);
+       fSettings.AddMessage(stateName.String(), stateMessage);
 }
 
 

############################################################################

Revision:    hrev46926
Commit:      e9a0833a86246dde90eef56e09b36fc4069a5ee4
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e9a0833
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Feb 25 19:57:08 2014 UTC

ScreenSaverRunner: Fix segmentation fault loading bad screen saver.

When Settings.ModuleName() returned NULL here we got a segmentation fault
trying to access the pointer.

I ran into this trying to load up a non-screensaver executable in ScreenSaver,
it crashed instead of doing the right thing and refusing to load.

Also, since we go to the trouble of saving this to a variable, we should 
actually use it.

----------------------------------------------------------------------------

diff --git a/src/kits/screensaver/ScreenSaverRunner.cpp 
b/src/kits/screensaver/ScreenSaverRunner.cpp
index c651286..2eefca7 100644
--- a/src/kits/screensaver/ScreenSaverRunner.cpp
+++ b/src/kits/screensaver/ScreenSaverRunner.cpp
@@ -96,7 +96,7 @@ ScreenSaverRunner::_LoadAddOn()
        _CleanUp();
 
        const char* moduleName = fSettings.ModuleName();
-       if (*moduleName == '\0') {
+       if (moduleName == NULL || *moduleName == '\0') {
                Resume();
                return;
        }
@@ -134,7 +134,7 @@ ScreenSaverRunner::_LoadAddOn()
                        fprintf(stderr, "Unable to find the instantiation 
function.\n");
                } else {
                        BMessage state;
-                       fSettings.GetModuleState(fSettings.ModuleName(), 
&state);
+                       fSettings.GetModuleState(moduleName, &state);
                        fSaver = instantiate(&state, fAddonImage);
                }
 


Other related posts:

  • » [haiku-commits] haiku: hrev46926 - src/kits/screensaver src/preferences/screensaver headers/private/screen_saver - jscipione