@@ -509,12 +509,7 @@ bool PaymentServer::readPaymentRequestFromFile(const QString& filename, PaymentR
509509 }
510510
511511 // BIP70 DoS protection
512- if (f.size () > BIP70_MAX_PAYMENTREQUEST_SIZE) {
513- qWarning () << QString (" PaymentServer::%1: Payment request %2 is too large (%3 bytes, allowed %4 bytes)." )
514- .arg (__func__)
515- .arg (filename)
516- .arg (f.size ())
517- .arg (BIP70_MAX_PAYMENTREQUEST_SIZE);
512+ if (!verifySize (f.size ())) {
518513 return false ;
519514 }
520515
@@ -685,14 +680,13 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
685680 reply->deleteLater ();
686681
687682 // BIP70 DoS protection
688- if (reply->size () > BIP70_MAX_PAYMENTREQUEST_SIZE) {
689- QString msg = tr (" Payment request %1 is too large (%2 bytes, allowed %3 bytes)." )
690- .arg (reply->request ().url ().toString ())
691- .arg (reply->size ())
692- .arg (BIP70_MAX_PAYMENTREQUEST_SIZE);
693-
694- qWarning () << QString (" PaymentServer::%1:" ).arg (__func__) << msg;
695- Q_EMIT message (tr (" Payment request DoS protection" ), msg, CClientUIInterface::MSG_ERROR);
683+ if (!verifySize (reply->size ())) {
684+ Q_EMIT message (tr (" Payment request rejected" ),
685+ tr (" Payment request %1 is too large (%2 bytes, allowed %3 bytes)." )
686+ .arg (reply->request ().url ().toString ())
687+ .arg (reply->size ())
688+ .arg (BIP70_MAX_PAYMENTREQUEST_SIZE),
689+ CClientUIInterface::MSG_ERROR);
696690 return ;
697691 }
698692
@@ -790,6 +784,18 @@ bool PaymentServer::verifyExpired(const payments::PaymentDetails& requestDetails
790784 return fVerified ;
791785}
792786
787+ bool PaymentServer::verifySize (qint64 requestSize)
788+ {
789+ bool fVerified = (requestSize <= BIP70_MAX_PAYMENTREQUEST_SIZE);
790+ if (!fVerified ) {
791+ qWarning () << QString (" PaymentServer::%1: Payment request too large (%2 bytes, allowed %3 bytes)." )
792+ .arg (__func__)
793+ .arg (requestSize)
794+ .arg (BIP70_MAX_PAYMENTREQUEST_SIZE);
795+ }
796+ return fVerified ;
797+ }
798+
793799bool PaymentServer::verifyAmount (const CAmount& requestAmount)
794800{
795801 bool fVerified = MoneyRange (requestAmount);
0 commit comments