# HG changeset patch # User Andrew Azores # Date 1406812592 14400 # Node ID cc873afa26d12cf19e82a770f5d5f7c7e552c751 # Parent fe3feb87ede1c3a9048b7e915c449329cefa5310 Fixes for coverity issues discovered in RH1121549 2014-07-30 Andrew Azores Fixes for coverity issues discovered in RH1121549 * plugin/icedteanp/IcedTeaNPPlugin.cc (ITNP_New): print error message and return error if JVM fails to start. (NP_Initialize): fix missing argument to PLUGIN_ERROR when unable to create data directory * plugin/icedteanp/IcedTeaParseProperties.cc (get_log_dir): refactored to reduce duplicate code, and added debug warning messages * plugin/icedteanp/IcedTeaScriptablePluginObject.cc (setProperty): do not erroneously redeclare java_result * tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc (file_exists): added assertion that directories satisfy file_exist diff -r fe3feb87ede1 -r cc873afa26d1 ChangeLog --- a/ChangeLog Wed Jul 30 14:22:13 2014 -0400 +++ b/ChangeLog Thu Jul 31 09:16:32 2014 -0400 @@ -1,3 +1,17 @@ +2014-07-30 Andrew Azores + + Fixes for coverity issues discovered in RH1121549 + * plugin/icedteanp/IcedTeaNPPlugin.cc (ITNP_New): print error message and + return error if JVM fails to start. + (NP_Initialize): fix missing argument to PLUGIN_ERROR when unable to + create data directory + * plugin/icedteanp/IcedTeaParseProperties.cc (get_log_dir): refactored to + reduce duplicate code, and added debug warning messages + * plugin/icedteanp/IcedTeaScriptablePluginObject.cc (setProperty): do not + erroneously redeclare java_result + * tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc (file_exists): added + assertion that directories satisfy file_exist + 2014-07-30 Jie Kang *NEWS: mentioned fixes to Java Console and itweb-settings UI. PR1856, 1857, diff -r fe3feb87ede1 -r cc873afa26d1 NEWS --- a/NEWS Wed Jul 30 14:22:13 2014 -0400 +++ b/NEWS Thu Jul 31 09:16:32 2014 -0400 @@ -19,6 +19,7 @@ - PR1859: Java Console UI improvement for lower resolutions (800*600) * Plugin - PR1743 - Intermittant deadlock in PluginRequestProcessor + - RH1121549: coverity defects * PolicyEditor - codebases without permissions assigned save to file anyway (and re-appear on next open) - PR1776: NullPointer on save-and-exit diff -r fe3feb87ede1 -r cc873afa26d1 plugin/icedteanp/IcedTeaNPPlugin.cc --- a/plugin/icedteanp/IcedTeaNPPlugin.cc Wed Jul 30 14:22:13 2014 -0400 +++ b/plugin/icedteanp/IcedTeaNPPlugin.cc Thu Jul 31 09:16:32 2014 -0400 @@ -373,6 +373,10 @@ // start the jvm if needed NPError startup_error = start_jvm_if_needed(); + if (startup_error != NPERR_NO_ERROR) { + PLUGIN_ERROR ("Failed to start JVM\n"); + return startup_error; + } // Initialize data->instance_id. // @@ -2025,7 +2029,7 @@ NPError np_error = initialize_data_directory(); if (np_error != NPERR_NO_ERROR) { - PLUGIN_ERROR("Unable create data directory %s\n"); + PLUGIN_ERROR("Unable to create data directory %s\n", data_directory.c_str()); return np_error; } diff -r fe3feb87ede1 -r cc873afa26d1 plugin/icedteanp/IcedTeaParseProperties.cc --- a/plugin/icedteanp/IcedTeaParseProperties.cc Wed Jul 30 14:22:13 2014 -0400 +++ b/plugin/icedteanp/IcedTeaParseProperties.cc Thu Jul 31 09:16:32 2014 -0400 @@ -123,39 +123,39 @@ return string(mypasswd->pw_dir)+"/.config/icedtea-web/"+default_file_ITW_deploy_props_name; } -string get_log_dir(){ +string get_log_dir(){ string value; if (!read_deploy_property_value("deployment.user.logdir", value)) { - int myuid = getuid(); - struct passwd *mypasswd = getpwuid(myuid); - // try pre 1.5 file location + string config_dir; if (getenv ("XDG_CONFIG_HOME") != NULL){ - string r1= string(getenv ("XDG_CONFIG_HOME"))+"/icedtea-web"; - string r2 = r1+"/"+default_itw_log_dir_name; - if (!IcedTeaPluginUtilities::file_exists(r1)){ - g_mkdir(r1.c_str(), 755); - } - if (!IcedTeaPluginUtilities::file_exists(r2)){ - g_mkdir(r2.c_str(), 755); - } - return r2; + config_dir = string(getenv("XDG_CONFIG_HOME")); + } else { + int myuid = getuid(); + struct passwd *mypasswd = getpwuid(myuid); + config_dir = string(mypasswd->pw_dir) + "/.config"; } - //if not then use default - string r1 = string(mypasswd->pw_dir)+"/.config/icedtea-web"; - string r2 = r1+"/"+default_itw_log_dir_name; - if (!IcedTeaPluginUtilities::file_exists(r1)){ - g_mkdir(r1.c_str(), 755); - } - if (!IcedTeaPluginUtilities::file_exists(r2)){ - g_mkdir(r2.c_str(), 755); - } - return r2; + string itw_dir = config_dir+"/icedtea-web"; + string log_dir = itw_dir+"/"+default_itw_log_dir_name; + mkdir_checked(itw_dir); + mkdir_checked(log_dir); + return log_dir; } return value; } +void mkdir_checked(string dir){ + if (!IcedTeaPluginUtilities::file_exists(dir)) + { + const int PERMISSIONS_MASK = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; // 0755 + int stat = g_mkdir(dir.c_str(), PERMISSIONS_MASK); + if (stat != 0) + { + PLUGIN_DEBUG("WARNING: Creation of directory %s failed: %s\n", dir.c_str(), strerror(errno)); + } + } +} -string main_properties_file(){ +string main_properties_file(){ return "/etc/.java/deployment/"+default_file_ITW_deploy_props_name; } diff -r fe3feb87ede1 -r cc873afa26d1 plugin/icedteanp/IcedTeaParseProperties.h --- a/plugin/icedteanp/IcedTeaParseProperties.h Wed Jul 30 14:22:13 2014 -0400 +++ b/plugin/icedteanp/IcedTeaParseProperties.h Thu Jul 31 09:16:32 2014 -0400 @@ -45,6 +45,7 @@ //public api std::string user_properties_file(); std::string get_log_dir(); +void mkdir_checked(std::string); bool find_system_config_file(std::string& dest); bool find_custom_jre(std::string& dest); bool read_deploy_property_value(std::string property, std::string& dest); diff -r fe3feb87ede1 -r cc873afa26d1 plugin/icedteanp/IcedTeaScriptablePluginObject.cc --- a/plugin/icedteanp/IcedTeaScriptablePluginObject.cc Wed Jul 30 14:22:13 2014 -0400 +++ b/plugin/icedteanp/IcedTeaScriptablePluginObject.cc Thu Jul 31 09:16:32 2014 -0400 @@ -704,7 +704,7 @@ browser_functions.intfromidentifier(name_id) >= 0) // else if array and requesting index { - JavaResultData* java_result = java_request.getArrayLength(instance_id); + java_result = java_request.getArrayLength(instance_id); if (java_result->error_occurred) { PLUGIN_ERROR("ERROR: Couldn't fetch array length\n"); diff -r fe3feb87ede1 -r cc873afa26d1 tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc --- a/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc Wed Jul 30 14:22:13 2014 -0400 +++ b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc Thu Jul 31 09:16:32 2014 -0400 @@ -135,6 +135,12 @@ remove(f1.c_str()); bool b = IcedTeaPluginUtilities::file_exists(f1); CHECK_EQUAL(b, false); + + std::string dir = tmpnam(NULL); + const int PERMISSIONS_MASK = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; // 0755 + bool created_dir = g_mkdir(dir.c_str(), PERMISSIONS_MASK); + CHECK_EQUAL(created_dir, false); + CHECK_EQUAL(IcedTeaPluginUtilities::file_exists(dir), true); }