[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Fix number parsing.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Fix number parsing. |
Date: |
Mon, 09 Aug 2021 20:59:53 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 0376eec Fix number parsing.
0376eec is described below
commit 0376eecc51832a2413acbdb122eaa4175ecf0382
Author: ms <ms@taler.net>
AuthorDate: Mon Aug 9 20:58:07 2021 +0200
Fix number parsing.
Sanity-checking input (number-)strings with RegEx.
---
.../main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 12 ++++++++++++
util/src/main/kotlin/Errors.kt | 7 ++++++-
util/src/main/kotlin/amounts.kt | 2 ++
util/src/main/kotlin/strings.kt | 13 ++++++++++++-
4 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
index 83e77f3..9e07004 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -19,6 +19,7 @@
package tech.libeufin.nexus.server
+import UtilError
import com.fasterxml.jackson.core.util.DefaultIndenter
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
import com.fasterxml.jackson.databind.JsonNode
@@ -196,6 +197,17 @@ fun serverMain(host: String, port: Int) {
)
)
}
+ exception<UtilError> { cause ->
+ logger.error("Exception while handling '${call.request.uri}'",
cause)
+ call.respond(
+ cause.statusCode,
+ message = ErrorResponse(
+ code = cause.ec?.code ?:
TalerErrorCode.TALER_EC_NONE.code,
+ hint = "see detail",
+ detail = cause.reason,
+ )
+ )
+ }
exception<EbicsProtocolError> { cause ->
logger.error("Caught exception while handling
'${call.request.uri}' (${cause.reason})")
call.respond(
diff --git a/util/src/main/kotlin/Errors.kt b/util/src/main/kotlin/Errors.kt
index 388ef18..86970f2 100644
--- a/util/src/main/kotlin/Errors.kt
+++ b/util/src/main/kotlin/Errors.kt
@@ -1,4 +1,5 @@
import io.ktor.http.*
+import tech.libeufin.util.TalerErrorCode
import kotlin.system.exitProcess
/*
@@ -20,7 +21,11 @@ import kotlin.system.exitProcess
* <http://www.gnu.org/licenses/>
*/
-data class UtilError(val statusCode: HttpStatusCode, val reason: String) :
+data class UtilError(
+ val statusCode: HttpStatusCode,
+ val reason: String,
+ val ec: TalerErrorCode?
+) :
Exception("$reason (HTTP status $statusCode)")
/**
diff --git a/util/src/main/kotlin/amounts.kt b/util/src/main/kotlin/amounts.kt
index 04543f8..19446db 100644
--- a/util/src/main/kotlin/amounts.kt
+++ b/util/src/main/kotlin/amounts.kt
@@ -1,6 +1,8 @@
import io.ktor.http.*
+import tech.libeufin.util.Amount
import tech.libeufin.util.AmountWithCurrency
import tech.libeufin.util.EbicsProtocolError
+import java.math.BigDecimal
/*
* This file is part of LibEuFin.
diff --git a/util/src/main/kotlin/strings.kt b/util/src/main/kotlin/strings.kt
index 1460125..7fd464c 100644
--- a/util/src/main/kotlin/strings.kt
+++ b/util/src/main/kotlin/strings.kt
@@ -21,6 +21,7 @@ package tech.libeufin.util
import UtilError
import io.ktor.http.HttpStatusCode
+import validatePlainAmount
import java.math.BigInteger
import java.math.BigDecimal
import java.util.*
@@ -104,10 +105,20 @@ data class AmountWithCurrency(
)
fun parseDecimal(decimalStr: String): BigDecimal {
+ if(!validatePlainAmount(decimalStr))
+ throw UtilError(
+ HttpStatusCode.BadRequest,
+ "Bad string amount given: $decimalStr",
+ TalerErrorCode.TALER_EC_GENERIC_PARAMETER_MALFORMED
+ )
return try {
BigDecimal(decimalStr)
} catch (e: NumberFormatException) {
- throw UtilError(HttpStatusCode.BadRequest, "Bad string amount given:
$decimalStr")
+ throw UtilError(
+ HttpStatusCode.BadRequest,
+ "Bad string amount given: $decimalStr",
+ TalerErrorCode.TALER_EC_GENERIC_PARAMETER_MALFORMED
+ )
}
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Fix number parsing.,
gnunet <=