Bugzilla – Attachment 163343 Details for
Bug 35129
REST API: _per_page=0 crashes on Illegal division by zero
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35129: Return 400 if _per_page=0 passed
Bug-35129-Return-400-if-perpage0-passed.patch (text/plain), 1.42 KB, created by
Tomás Cohen Arazi
on 2024-03-18 15:53:58 UTC
(
hide
)
Description:
Bug 35129: Return 400 if _per_page=0 passed
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2024-03-18 15:53:58 UTC
Size:
1.42 KB
patch
obsolete
>From 3618748f9fff8d954180e1070a15227fa2d7f77f Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 18 Mar 2024 12:49:20 -0300 >Subject: [PATCH] Bug 35129: Return 400 if _per_page=0 passed > >This patch adds a safe guard for when consumers pass _per_page=0 to >endpoints. This condition is checked for on a centralized place and >avoid reaching the controller in such scenarios that would provoke a >division by zero exception. > >To test: >1. Apply the regression tests patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/pagination.t >=> FAIL: We expect a 400, but get a 500 instead >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Tests pass! No more explosions for this! >5. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/REST/V1/Auth.pm | 3 +++ > 1 file changed, 3 insertions(+) > >diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm >index 948bed689bd..b8d793b0f68 100644 >--- a/Koha/REST/V1/Auth.pm >+++ b/Koha/REST/V1/Auth.pm >@@ -358,6 +358,9 @@ sub validate_query_parameters { > push @errors, { path => "/query/" . $param, message => 'Malformed query string' } unless exists $valid_parameters{$param}; > } > >+ push @errors, { path => "/query/_per_page", message => 'Invalid value: 0' } >+ if exists $existing_params->{_per_page} && $existing_params->{_per_page} == 0; >+ > Koha::Exceptions::BadParameter->throw( > error => \@errors > ) if @errors; >-- >2.44.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35129
:
163342
|
163343
|
163637
|
163638
|
164222
|
164223