Skip to content

Commit

Permalink
Fix ut-of-bounds read inside norm_inf by returning 0.0 for 0 len arra…
Browse files Browse the repository at this point in the history
…ys in norm_inf, closes #284 (#285)
  • Loading branch information
bodono authored Aug 24, 2024
1 parent 911cb49 commit 339ca81
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/linalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ scs_float SCS(norm_inf)(const scs_float *a, scs_int len) {
*/

scs_float SCS(norm_inf)(const scs_float *a, scs_int len) {
/* Follow the semantics of BLASI(lange) for zero-size array. */
scs_int idx;
blas_int bone = 1;
blas_int blen = (blas_int)len;
scs_int idx = (scs_int)BLASI(amax)(&blen, a, &bone);
if (len <= 0) {
return 0.0;
}
idx = (scs_int)BLASI(amax)(&blen, a, &bone);
/* Returned idx is 1-based. */
return ABS(a[idx - 1]);
}
Expand Down

0 comments on commit 339ca81

Please sign in to comment.