summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorOmar Polo <op@cvs.openbsd.org>2024-08-27 18:45:59 +0000
committerOmar Polo <op@cvs.openbsd.org>2024-08-27 18:45:59 +0000
commit783db51cf3eb24d5bdf5aba1511256c3aff2022b (patch)
tree75fbcb7b5e02cc741e3666d768729faabba49b0b /bin
parentf7556979deda98d0aedf82a12c7b30ad9e520e1f (diff)
ksh: use strtonum() in findhistrel()
ok millert@, deraadt@
Diffstat (limited to 'bin')
-rw-r--r--bin/ksh/history.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/bin/ksh/history.c b/bin/ksh/history.c
index c768563496e..6f4a1c8e571 100644
--- a/bin/ksh/history.c
+++ b/bin/ksh/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.84 2019/10/27 15:02:19 jca Exp $ */
+/* $OpenBSD: history.c,v 1.85 2024/08/27 18:45:58 op Exp $ */
/*
* command history
@@ -507,19 +507,19 @@ findhist(int start, int fwd, const char *str, int anchored)
int
findhistrel(const char *str)
{
+ const char *errstr;
int maxhist = histptr - history;
int start = maxhist - 1;
- int rec = atoi(str);
+ int rec;
+
+ rec = strtonum(str, -maxhist, maxhist, &errstr);
+ if (errstr)
+ return -1;
if (rec == 0)
return -1;
- if (rec > 0) {
- if (rec > maxhist)
- return -1;
+ if (rec > 0)
return rec - 1;
- }
- if (rec > maxhist)
- return -1;
return start + rec + 1;
}