Bugzilla – Attachment 164223 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.54 KB, created by
Nick Clemens (kidclamp)
on 2024-04-01 17:50:19 UTC
(
hide
)
Description:
Bug 35129: Return 400 if _per_page=0 passed
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-04-01 17:50:19 UTC
Size:
1.54 KB
patch
obsolete
>From 436088e29ef4afa4b56961718ae8c9a88346c54d 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> >Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > 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.30.2
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