Without these checks in both functions nw = n / BN_BITS2 will be negative
and this leads to out-of-bounds accesses via negative array indices and
memset with a negative size.
Pointed out by cheloha
ok jsing
-/* $OpenBSD: bn_shift.c,v 1.13 2014/10/28 07:35:58 jsg Exp $ */
+/* $OpenBSD: bn_shift.c,v 1.14 2022/06/22 09:03:06 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include <stdio.h>
#include <string.h>
+#include <openssl/err.h>
+
#include "bn_lcl.h"
int
BN_ULONG *t, *f;
BN_ULONG l;
+ if (n < 0) {
+ BNerror(BN_R_INVALID_LENGTH);
+ return 0;
+ }
+
bn_check_top(r);
bn_check_top(a);
BN_ULONG *t, *f;
BN_ULONG l, tmp;
+ if (n < 0) {
+ BNerror(BN_R_INVALID_LENGTH);
+ return 0;
+ }
+
bn_check_top(r);
bn_check_top(a);