Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit a84507a

Browse files
author
Chris Board
committed
Fixed issue where COM_QueryResponse would inadvertently detect a MySQL Error packet and then throw an error because it wasn't actually a MySQL Error Packet.
1 parent 2726401 commit a84507a

File tree

17 files changed

+252
-185
lines changed

17 files changed

+252
-185
lines changed

.idea/compiler.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AndroidMySQLConnector/build.gradle

+21-12
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ buildscript {
88
}
99
}
1010
}
11-
11+
apply plugin: 'maven-publish'
1212
apply plugin: 'com.android.library'
1313
if (rootProject.ext.publishToMavenLocal)
1414
{
15+
println("using maven local")
1516
apply plugin: 'maven-publish'
1617
}
1718
else
1819
{
20+
println("Not using maven local")
1921
apply plugin: 'com.github.dcendents.android-maven'
2022
}
2123

@@ -25,11 +27,11 @@ group 'com.BoardiesITSolutions'
2527

2628

2729
android {
28-
compileSdkVersion 30
30+
compileSdk 33
2931
defaultConfig {
3032
//applicationId "com.BoardiesITSolutions.AndroidMySQLConnector"
3133
minSdkVersion 19
32-
targetSdkVersion 30
34+
targetSdkVersion 33
3335
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3436
}
3537
buildTypes {
@@ -43,16 +45,23 @@ android {
4345
abortOnError false
4446
}
4547

46-
48+
println("Is publishToMavenLocal set? " + rootProject.ext.publishToMavenLocal)
4749
if (rootProject.ext.publishToMavenLocal) {
4850
android.libraryVariants
4951

50-
publishing {
51-
publications {
52-
maven(MavenPublication)
53-
{
54-
artifact getArtifactFullPath()
55-
}
52+
project.afterEvaluate {
53+
project.publishing {
54+
publications {
55+
mavenJava(MavenPublication) {
56+
groupId 'com.BoardiesITSolutions'
57+
artifactId 'AndroidMySQLConnector'
58+
version '0.49'
59+
artifact("$buildDir/outputs/aar/AndroidMySQLConnector-release.aar")
60+
}
61+
}
62+
repositories {
63+
mavenLocal()
64+
}
5665
}
5766
}
5867

@@ -89,6 +98,6 @@ def getArtifactFullPath() {
8998

9099
dependencies {
91100
implementation fileTree(dir: 'libs', include: ['*.jar'])
92-
implementation 'androidx.appcompat:appcompat:1.2.0'
93-
implementation("com.google.guava:guava:28.2-android")
101+
implementation 'androidx.appcompat:appcompat:1.6.1'
102+
implementation('com.google.guava:guava:32.1.3-jre')
94103
}

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/Exceptions/InvalidSQLPacketException.java

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ public class InvalidSQLPacketException extends Exception
55
public InvalidSQLPacketException(String message)
66
{
77
super(message);
8+
this.printStackTrace();
89
}
910
}

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/Helpers.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.BoardiesITSolutions.AndroidMySQLConnector;
22

3+
import android.util.Log;
4+
35
import com.BoardiesITSolutions.AndroidMySQLConnector.Exceptions.MySQLConnException;
46
import com.BoardiesITSolutions.AndroidMySQLConnector.Exceptions.MySQLException;
57

@@ -30,6 +32,7 @@ public static MYSQL_PACKET_TYPE getMySQLPacketType(byte[] socketData) throws IOE
3032
}
3133

3234
int packetType = socketData[4] & 0xff;
35+
Log.d("Helpers", "Get MySQL Packet Type. Packet Type: " + packetType + " Before Modding: " + socketData[4]);
3336
if ((packetType & 0xff) == 0xff)
3437
{
3538
return MYSQL_PACKET_TYPE.MYSQL_ERROR_PACKET;

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/MySQLIO.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Arrays;
1616
import java.util.List;
1717
import java.util.concurrent.Semaphore;
18+
import java.util.logging.Logger;
1819

1920
import javax.net.ssl.SSLSocket;
2021

@@ -118,34 +119,39 @@ private void getSocketData() throws IOException
118119
//continue fetching data
119120
if (!isDBConnected)
120121
{
122+
Log.d("MySQLIO", "DB Is Not Connected. Breaking MySQLIO");
121123
break;
122124
}
123125
else {
124126
int packetType = tempFullData[tempFullData.length - 1];
127+
Log.d("MySQLIO", "Packet Type: " + String.valueOf(packetType) + " at position: " + String.valueOf(tempFullData.length - 1));
125128
Log.d("MySQIO", "Less than 1024 Bytes Returned. Packet Type at end of array (end of array would have to be an OK: " + packetType);
126129
if (packetType == 0x00 || packetType == 0xfe)
127130
{
131+
Log.d("MySQLIO", "Breaking MySQLIO due to OK packet at end of array");
128132
break;
129133
}
130134
packetType = tempFullData[tempFullData.length-1 - 8];
131135
Log.d("MySQIO", "Less than 1024 bytes returned. Packet type -8 from the end of the array would need to be an EOF packet");
132136
if (packetType == 0xfe || packetType == 0xff)
133137
{
138+
Log.d("MySQLIO", "Breaking MySQLIO due to OK packet at end of array -8 bytes");
134139
break;
135140
}
136141
//The 4th byte can also contain the OK or EOF so check this as well
137142
if (tempFullData[4] == 0x00 || tempFullData[4] == 0xfe || tempFullData[4] == 0xff)
138143
{
144+
Log.d("MySQLIO", "Breaking MySQLIO due to OK packet at byte 4");
139145
break;
140146
}
141-
Log.d("MySQIO", "Packet Type at -8 was: " + packetType + " so continuing fetching data");
147+
Log.d("MySQIO", "Packet Type at -8 was: " + packetType + " so continuing fetching data");
142148

143-
if (expectedPayloadLength == (tempFullData.length - 4))
144-
{
145-
break;
146-
}
149+
if (expectedPayloadLength == (tempFullData.length - 4))
150+
{
151+
Log.d("MySQLIO", "Breaking MySQLIO due to expected payload length");
152+
break;
147153
}
148-
//If we get here continue fetching data
154+
}
149155

150156
}
151157
}

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/PacketManager/COM_QueryResponse.java

+1-27
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,11 @@ private void processPacketData()
110110
{
111111
break;
112112
}
113-
this.mysqlConn.getMysqlIO().shiftCurrentBytePosition(4);
114-
115-
//Check we don't have an error packet
116-
if (Helpers.getMySQLPacketTypeFromIntWithoutShift(packetType) == Helpers.MYSQL_PACKET_TYPE.MYSQL_ERROR_PACKET)
117-
{
118-
try {
119-
MySQLErrorPacket errorPacket = new MySQLErrorPacket(this.mysqlConn);
120-
throw new MySQLException(errorPacket.getErrorMsg(), errorPacket.getErrorCode(), errorPacket.getSqlState());
121-
}
122-
catch (Exception ex)
123-
{
124-
Log.e("COM_QueryResponse", ex.toString());
125-
}
126-
break;
127-
}
128-
129-
130113

114+
this.mysqlConn.getMysqlIO().shiftCurrentBytePosition(4);
131115

132116
MySQLRow row = new MySQLRow();
133117

134-
/*if (Helpers.getMySQLPacketTypeFromIntWithoutShift(packetType) == Helpers.MYSQL_PACKET_TYPE.MYSQL_EOF_PACKET
135-
|| Helpers.getMySQLPacketTypeFromIntWithoutShift(packetType) == Helpers.MYSQL_PACKET_TYPE.MYSQL_OK_PACKET)
136-
{
137-
Log.d("COM_QueryResponse", "Got EOF or OK Packet. Breaking from loop");
138-
//We've got an EOF packet so we're at the end or an OK packet so we've got everything we need
139-
break;
140-
}*/
141-
142118
int currentColumn = 0;
143119
for (; currentColumn < numberOfFields; currentColumn++)
144120
{
@@ -212,8 +188,6 @@ private void processPacketData()
212188
}
213189
timesProcessed++;
214190
}while(true);
215-
216-
217191
}
218192

219193
public List<ColumnDefinition> getColumnDefinitions()

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/PacketManager/MySQLErrorPacket.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void processPacket() throws IOException, InvalidSQLPacketException, MySQ
4545
this.setPacketSequenceNumber((byte)this.mysqlConn.getMysqlIO().extractData(1));
4646

4747

48-
if (Helpers.getMySQLPacketType(this.mysqlConn.getMysqlIO().getSocketByteArray()) != Helpers.MYSQL_PACKET_TYPE.MYSQL_ERROR_PACKET) {
48+
if (Helpers.getMySQLPacketTypeFromIntWithoutShift(this.mysqlConn.getMysqlIO().readCurrentByteWithoutShift()) != Helpers.MYSQL_PACKET_TYPE.MYSQL_ERROR_PACKET) {
4949
throw new InvalidSQLPacketException("Error: Trying to process a MySQL Error Packet but we don't have the expected packet header for a MySQL Error Packet");
5050
}
5151

AndroidMySQLConnector/src/main/java/com/BoardiesITSolutions/AndroidMySQLConnector/Statement.java

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ public void run()
218218
}
219219
}
220220
catch (final InvalidSQLPacketException e) {
221+
Log.e("Statement", "Invalid SQL Packet Exception in Statement");
222+
e.printStackTrace();
221223
if (mysqlConn.getReturnCallbackToMainThread()) {
222224
mysqlConn.getActivity().runOnUiThread(new Runnable() {
223225
@Override
@@ -263,6 +265,7 @@ public void run()
263265
}
264266
catch (final MySQLConnException ex)
265267
{
268+
ex.printStackTrace();
266269
if (mysqlConn.getReturnCallbackToMainThread())
267270
{
268271
mysqlConn.getActivity().runOnUiThread(new Runnable() {

build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ buildscript {
77
publishToMavenLocal = false
88
}
99

10+
11+
1012
repositories {
1113
if (publishToMavenLocal)
1214
{
15+
println("Top level build gradle. Using mavenLocal")
16+
apply plugin: 'maven-publish'
1317
mavenLocal()
1418
}
1519
jcenter()
1620
google()
1721
}
1822
dependencies {
19-
classpath 'com.android.tools.build:gradle:4.2.2'
23+
classpath 'com.android.tools.build:gradle:7.4.2'
2024
if (!publishToMavenLocal) {
2125
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
2226
}

demoapplication/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 29
4+
compileSdk 33
55

66

77
defaultConfig {
88
applicationId "com.boardiesitsolutions.demoapplication"
99
minSdkVersion 19
10-
targetSdkVersion 29
10+
targetSdkVersion 33
1111
versionCode 1
1212
versionName "1.0"
1313

@@ -30,7 +30,7 @@ android {
3030
dependencies {
3131
implementation fileTree(dir: 'libs', include: ['*.jar'])
3232

33-
implementation 'androidx.appcompat:appcompat:1.2.0'
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
3434
implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.49_MySQL8'
3535

3636
}

demoapplication/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
android:roundIcon="@mipmap/ic_launcher_round"
88
android:supportsRtl="true"
99
android:theme="@style/AppTheme">
10-
<activity android:name=".MainActivity">
10+
<activity android:name=".MainActivity"
11+
android:exported="true">
1112
<intent-filter>
1213
<action android:name="android.intent.action.MAIN" />
1314
<category android:name="android.intent.category.LAUNCHER" />

gradle/wrapper/gradle-wrapper.jar

4.71 KB
Binary file not shown.
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Mar 17 18:05:39 GMT 2021
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

0 commit comments

Comments
 (0)