You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2024/09/09 14:34:00 UTC
[jira] [Work logged] (ARTEMIS-4965) Possible null dereference when property is missing in journal-sql.properties file
[ https://issues.apache.org/jira/browse/ARTEMIS-4965?focusedWorklogId=933828&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-933828 ]
ASF GitHub Bot logged work on ARTEMIS-4965:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 09/Sep/24 14:33
Start Date: 09/Sep/24 14:33
Worklog Time Spent: 10m
Work Description: gemmellr commented on code in PR #5194:
URL: https://github.com/apache/activemq-artemis/pull/5194#discussion_r1750378128
##########
artemis-jdbc-store/src/test/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProviderTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jdbc.store.sql;
+
+import java.sql.DriverManager;
+
+import org.apache.activemq.artemis.tests.util.ArtemisTestCase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider.Factory.SQLDialect.DERBY;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class PropertySQLProviderTest extends ArtemisTestCase {
+
+ @Test
+ public void testGetProperty() {
+ for (SQLProvider.DatabaseStoreType storeType : SQLProvider.DatabaseStoreType.values()) {
+ PropertySQLProvider factory = (PropertySQLProvider) new PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
+ factory.sql("create-file-table");
+ }
+ }
+
+ @Test
+ public void testGetMissingProperty() {
+ for (SQLProvider.DatabaseStoreType storeType : SQLProvider.DatabaseStoreType.values()) {
+ try {
+ PropertySQLProvider factory = (PropertySQLProvider) new PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
Review Comment:
Shouldnt this be outside the try?
##########
artemis-jdbc-store/src/test/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProviderTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jdbc.store.sql;
+
+import java.sql.DriverManager;
+
+import org.apache.activemq.artemis.tests.util.ArtemisTestCase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider.Factory.SQLDialect.DERBY;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class PropertySQLProviderTest extends ArtemisTestCase {
+
+ @Test
+ public void testGetProperty() {
+ for (SQLProvider.DatabaseStoreType storeType : SQLProvider.DatabaseStoreType.values()) {
+ PropertySQLProvider factory = (PropertySQLProvider) new PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
+ factory.sql("create-file-table");
+ }
+ }
+
+ @Test
+ public void testGetMissingProperty() {
+ for (SQLProvider.DatabaseStoreType storeType : SQLProvider.DatabaseStoreType.values()) {
+ try {
+ PropertySQLProvider factory = (PropertySQLProvider) new PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
+ factory.sql("foo");
Review Comment:
Your first attempt failed some tests because it didnt allow for returning null as expected in a specific case. You have updated things to fix that by allowing the behaviour to be specified, but dont seem to be testing the new mechanism. Seems like there should be a related variant of this test to cover that.
Also, perhaps use e.g "missing-property" as the key name for later clarity?
##########
artemis-jdbc-store/src/test/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProviderTest.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.jdbc.store.sql;
+
+import java.sql.DriverManager;
+
+import org.apache.activemq.artemis.tests.util.ArtemisTestCase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider.Factory.SQLDialect.DERBY;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class PropertySQLProviderTest extends ArtemisTestCase {
+
+ @Test
+ public void testGetProperty() {
+ for (SQLProvider.DatabaseStoreType storeType : SQLProvider.DatabaseStoreType.values()) {
+ PropertySQLProvider factory = (PropertySQLProvider) new PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
+ factory.sql("create-file-table");
+ }
+ }
+
+ @Test
+ public void testGetMissingProperty() {
+ for (SQLProvider.DatabaseStoreType storeType : SQLProvider.DatabaseStoreType.values()) {
+ try {
+ PropertySQLProvider factory = (PropertySQLProvider) new PropertySQLProvider.Factory(DERBY).create("who-cares", storeType);
+ factory.sql("foo");
+ fail();
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ }
+ }
+
+ @AfterEach
+ public void shutdownDerby() {
+ try {
+ DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (Exception ignored) {
+ }
Review Comment:
Probably nicer just to call DBSupportUtil._shutdownDerby_, which also e.g verifies the shutdown exception is as expected.
Issue Time Tracking
-------------------
Worklog Id: (was: 933828)
Time Spent: 40m (was: 0.5h)
> Possible null dereference when property is missing in journal-sql.properties file
> ---------------------------------------------------------------------------------
>
> Key: ARTEMIS-4965
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4965
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Reporter: Suhov Roman
> Assignee: Justin Bertram
> Priority: Major
> Time Spent: 40m
> Remaining Estimate: 0h
>
> File: https://github.com/apache/activemq-artemis/blob/main/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProvider.java
> In lines 81,93,94,95,101,106,111,116 and further in the PropertySQLProvider class, where properties are received from the journal-sql.properties file, a null dereference is possible.
> A dereference can occur if the required property is missing from the journal-sql.properties file. A null check must be added to all method return values.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@activemq.apache.org
For additional commands, e-mail: issues-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact