Discussion:
[PATCH] Added restriction on supported base value
Your Name
2018-08-11 17:16:07 UTC
Permalink
---
newlib/libc/stdlib/strtoimax.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/newlib/libc/stdlib/strtoimax.c b/newlib/libc/stdlib/strtoimax.c
index 6901612..1779d3b 100644
--- a/newlib/libc/stdlib/strtoimax.c
+++ b/newlib/libc/stdlib/strtoimax.c
@@ -90,7 +90,8 @@ _strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
}
if (base == 0)
base = c == '0' ? 8 : 10;
-
+ if (base < 2 || base > 36)
+ goto noconv;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
@@ -135,6 +136,7 @@ _strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
acc = neg ? INTMAX_MIN : INTMAX_MAX;
rptr->_errno = ERANGE;
} else if (!any) {
+noconv:
rptr->_errno = EINVAL;
} else if (neg)
acc = -acc;
--
2.7.4
Aditya Upadhyay
2018-08-11 17:27:48 UTC
Permalink
From: Your Name <***@example.com>

---
newlib/libc/stdlib/strtoimax.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/newlib/libc/stdlib/strtoimax.c b/newlib/libc/stdlib/strtoimax.c
index 6901612..1779d3b 100644
--- a/newlib/libc/stdlib/strtoimax.c
+++ b/newlib/libc/stdlib/strtoimax.c
@@ -90,7 +90,8 @@ _strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
}
if (base == 0)
base = c == '0' ? 8 : 10;
-
+ if (base < 2 || base > 36)
+ goto noconv;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
@@ -135,6 +136,7 @@ _strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
acc = neg ? INTMAX_MIN : INTMAX_MAX;
rptr->_errno = ERANGE;
} else if (!any) {
+noconv:
rptr->_errno = EINVAL;
} else if (neg)
acc = -acc;
--
2.7.4
Joel Sherrill
2018-08-11 19:51:26 UTC
Permalink
Your git configuration appears to be incorrectly configured.
Post by Your Name
---
newlib/libc/stdlib/strtoimax.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/newlib/libc/stdlib/strtoimax.c
b/newlib/libc/stdlib/strtoimax.c
index 6901612..1779d3b 100644
--- a/newlib/libc/stdlib/strtoimax.c
+++ b/newlib/libc/stdlib/strtoimax.c
@@ -90,7 +90,8 @@ _strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
}
if (base == 0)
base = c == '0' ? 8 : 10;
-
+ if (base < 2 || base > 36)
+ goto noconv;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
@@ -135,6 +136,7 @@ _strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
acc = neg ? INTMAX_MIN : INTMAX_MAX;
rptr->_errno = ERANGE;
} else if (!any) {
rptr->_errno = EINVAL;
} else if (neg)
acc = -acc;
--
2.7.4
Loading...