Skip to content

Commit

Permalink
Fix null pointer exception error.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jul 16, 2023
1 parent b65fca4 commit f7eb5c8
Show file tree
Hide file tree
Showing 47 changed files with 78 additions and 91 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Firebase Arduino Client Library for ESP8266 and ESP32",
"version": "4.3.16",
"version": "4.3.17",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "The library supports Firebase products e.g. Realtime database, Cloud Firestore database, Firebase Storage and Google Cloud Storage, Cloud Functions for Firebase and Cloud Messaging. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=Firebase Arduino Client Library for ESP8266 and ESP32

version=4.3.16
version=4.3.17

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Const.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Error.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Network.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/FB_Utils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Firebase.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/FirebaseFS.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/Firebase_Client_Version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef FIREBASE_CLIENT_VERSION
#define FIREBASE_CLIENT_VERSION "4.3.16"
#define FIREBASE_CLIENT_VERSION_NUM 40316
#define FIREBASE_CLIENT_VERSION "4.3.17"
#define FIREBASE_CLIENT_VERSION_NUM 40317

/* The inconsistent file version checking to prevent mixed versions compilation. */
#define FIREBASE_CLIENT_VERSION_CHECK(ver) (ver == FIREBASE_CLIENT_VERSION_NUM)
Expand Down
2 changes: 1 addition & 1 deletion src/firestore/FB_Firestore.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/firestore/FB_Firestore.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/functions/FB_Functions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/functions/FB_Functions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/functions/FunctionsConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/functions/FunctionsConfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/functions/PocicyBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/functions/PolicyBuilder.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/gcs/GCS.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/gcs/GCS.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/message/FCM.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/message/FCM.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/FB_RTDB.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/FB_RTDB.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueryFilter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueryFilter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/QueueManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_MP_Stream.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_MP_Stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_Stream.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/rtdb/stream/FB_Stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/session/FB_Session.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/session/FB_Session.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand Down
72 changes: 29 additions & 43 deletions src/signer/Signer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40316)
#if !FIREBASE_CLIENT_VERSION_CHECK(40317)
#error "Mixed versions compilation."
#endif

Expand All @@ -8,7 +8,7 @@
*
* This library supports Espressif ESP8266, ESP32 and Raspberry Pi Pico
*
* Created July 11, 2023
* Created July 16, 2023
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -286,6 +286,13 @@ bool Firebase_Signer::checkAuthTypeChanged(FirebaseConfig *config, FirebaseAuth

time_t Firebase_Signer::getTime()
{
// When the pointers are not yet initialized.
uint32_t ts = 0;
uint32_t ts_offset = 0;
if (!mb_ts)
mb_ts = &ts;
if (!ts_offset)
mb_ts_offset = &ts_offset;
return TimeHelper::getTime(mb_ts, mb_ts_offset);
}

Expand Down Expand Up @@ -1053,6 +1060,20 @@ bool Firebase_Signer::handleTokenResponse(int &httpCode)
return false;
}

bool Firebase_Signer::handleError(int code, const char *descr, int errNum)
{
#if defined(ESP32)
char *temp = MemoryHelper::createBuffer<char *>(mbfs, 100);
mbedtls_strerror(errNum, temp, 100);
config->signer.tokens.error.message = temp;
MemoryHelper::freeBuffer(mbfs, temp);
#endif
setTokenError(code);
config->signer.tokens.error.message.insert(0, descr);
sendTokenStatusCB();
return false;
}

bool Firebase_Signer::createJWT()
{

Expand Down Expand Up @@ -1192,15 +1213,8 @@ bool Firebase_Signer::createJWT()
config->signer.encHeadPayload.length(), config->signer.hash);
if (ret != 0)
{
char *temp = MemoryHelper::createBuffer<char *>(mbfs, 100);
mbedtls_strerror(ret, temp, 100);
config->signer.tokens.error.message = temp;
config->signer.tokens.error.message.insert(0, (const char *)FPSTR("mbedTLS, mbedtls_md: "));
MemoryHelper::freeBuffer(mbfs, temp);
setTokenError(FIREBASE_ERROR_TOKEN_CREATE_HASH);
sendTokenStatusCB();
MemoryHelper::freeBuffer(mbfs, config->signer.hash);
return false;
return handleError(FIREBASE_ERROR_TOKEN_CREATE_HASH, (const char *)FPSTR("mbedTLS, mbedtls_md: "), ret);
}
#elif defined(ESP8266) || defined(MB_ARDUINO_PICO)
config->signer.hash = MemoryHelper::createBuffer<char *>(Signer.mbfs, config->signer.hashSize);
Expand Down Expand Up @@ -1237,18 +1251,11 @@ bool Firebase_Signer::createJWT()

if (ret != 0)
{
char *temp = MemoryHelper::createBuffer<char *>(mbfs, 100);
mbedtls_strerror(ret, temp, 100);
config->signer.tokens.error.message = temp;
config->signer.tokens.error.message.insert(0, (const char *)FPSTR("mbedTLS, mbedtls_pk_parse_key: "));
MemoryHelper::freeBuffer(mbfs, temp);
setTokenError(FIREBASE_ERROR_TOKEN_PARSE_PK);
sendTokenStatusCB();
mbedtls_pk_free(config->signer.pk_ctx);
MemoryHelper::freeBuffer(mbfs, config->signer.hash);
delete config->signer.pk_ctx;
config->signer.pk_ctx = nullptr;
return false;
return handleError(FIREBASE_ERROR_TOKEN_PARSE_PK, (const char *)FPSTR("mbedTLS, mbedtls_pk_parse_key: "), ret);
}

// generate RSA signature from private key and message digest
Expand All @@ -1265,15 +1272,7 @@ bool Firebase_Signer::createJWT()
config->signer.signature, &sigLen,
mbedtls_ctr_drbg_random, config->signer.ctr_drbg_ctx);
if (ret != 0)
{
char *temp = MemoryHelper::createBuffer<char *>(mbfs, 100);
mbedtls_strerror(ret, temp, 100);
config->signer.tokens.error.message = temp;
config->signer.tokens.error.message.insert(0, (const char *)FPSTR("mbedTLS, mbedtls_pk_sign: "));
MemoryHelper::freeBuffer(mbfs, temp);
setTokenError(FIREBASE_ERROR_TOKEN_SIGN);
sendTokenStatusCB();
}
handleError(FIREBASE_ERROR_TOKEN_SIGN, (const char *)FPSTR("mbedTLS, mbedtls_pk_sign: "), ret);
else
{
config->signer.encSignature.clear();
Expand Down Expand Up @@ -1314,21 +1313,13 @@ bool Firebase_Signer::createJWT()
pk = new BearSSL::PrivateKey((const char *)config->service_account.data.private_key);

if (!pk)
{
setTokenError(FIREBASE_ERROR_TOKEN_PARSE_PK);
config->signer.tokens.error.message.insert(0, (const char *)FPSTR("BearSSL, PrivateKey: "));
sendTokenStatusCB();
return false;
}
return handleError(FIREBASE_ERROR_TOKEN_PARSE_PK, (const char *)FPSTR("BearSSL, PrivateKey: "));

if (!pk->isRSA())
{
setTokenError(FIREBASE_ERROR_TOKEN_PARSE_PK);
config->signer.tokens.error.message.insert(0, (const char *)FPSTR("BearSSL, isRSA: "));
sendTokenStatusCB();
delete pk;
pk = nullptr;
return false;
return handleError(FIREBASE_ERROR_TOKEN_PARSE_PK, (const char *)FPSTR("BearSSL, isRSA: "));
}

const br_rsa_private_key *br_rsa_key = pk->getRSA();
Expand Down Expand Up @@ -1359,12 +1350,7 @@ bool Firebase_Signer::createJWT()
config->signer.encSignature.clear();
}
else
{
setTokenError(FIREBASE_ERROR_TOKEN_SIGN);
config->signer.tokens.error.message.insert(0, (const char *)FPSTR("BearSSL, br_rsa_i15_pkcs1_sign: "));
sendTokenStatusCB();
return false;
}
return handleError(FIREBASE_ERROR_TOKEN_SIGN, (const char *)FPSTR("BearSSL, br_rsa_i15_pkcs1_sign: "));
#endif
}

Expand Down
Loading

0 comments on commit f7eb5c8

Please sign in to comment.