diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2007-01-20 06:57:55 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2007-01-20 06:57:55 +0000 |
commit | 51407b5525d8285b5c186dd3ca912056e93a69e8 (patch) | |
tree | d7bccf2c09a1abb36d503b4187dc2108bdf791f7 /usr.bin/rcs/date.y | |
parent | 31d17019c2911ac0469067ceb1d741c569c0558e (diff) |
Prevent negative array index accesses when strlen(buff) == 0.
OK joris@
Diffstat (limited to 'usr.bin/rcs/date.y')
-rw-r--r-- | usr.bin/rcs/date.y | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/usr.bin/rcs/date.y b/usr.bin/rcs/date.y index e5ed23c0180..5e08849ed0d 100644 --- a/usr.bin/rcs/date.y +++ b/usr.bin/rcs/date.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: date.y,v 1.4 2006/05/17 20:38:05 xsa Exp $ */ +/* $OpenBSD: date.y,v 1.5 2007/01/20 06:57:54 ray Exp $ */ /* ** Originally written by Steven M. Bellovin <smb@research.att.com> while @@ -628,6 +628,7 @@ RelativeMonth(time_t Start, time_t RelMonth) static int lookup(char *buff) { + size_t len; char *p, *q; int i, abbrev; const TABLE *tp; @@ -646,12 +647,14 @@ lookup(char *buff) return (tMERIDIAN); } + len = strlen(buff); /* See if we have an abbreviation for a month. */ - if (strlen(buff) == 3) + if (len == 3) abbrev = 1; - else if (strlen(buff) == 4 && buff[3] == '.') { + else if (len == 4 && buff[3] == '.') { abbrev = 1; buff[3] = '\0'; + --len; } else abbrev = 0; @@ -683,15 +686,14 @@ lookup(char *buff) } /* Strip off any plural and try the units table again. */ - i = strlen(buff) - 1; - if (buff[i] == 's') { - buff[i] = '\0'; + if (len != 0 && buff[len - 1] == 's') { + buff[len - 1] = '\0'; for (tp = UnitsTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; return (tp->type); } - buff[i] = 's'; /* Put back for "this" in OtherTable. */ + buff[len - 1] = 's'; /* Put back for "this" in OtherTable. */ } for (tp = OtherTable; tp->name; tp++) @@ -701,7 +703,7 @@ lookup(char *buff) } /* Military timezones. */ - if (buff[1] == '\0' && isalpha(*buff)) { + if (len == 1 && isalpha(*buff)) { for (tp = MilitaryTable; tp->name; tp++) if (strcmp(buff, tp->name) == 0) { yylval.Number = tp->value; |