From 72aed89a67c692a18dc654c3e3d5c1e3a3e31032 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Sun, 26 Aug 2007 20:40:55 +0000 Subject: [PATCH] Correct off-by-one error. When comparing the command names, we might wind up behind the array, later dereferencing a dangling pointer. Terminate the array correctly and stop processing soon enough. Additionally, correct the error output to use errx(), as there is no meaningful errno available. Differing behavior spotted by use of tinycc. --- usr.bin/objformat/objformat.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/usr.bin/objformat/objformat.c b/usr.bin/objformat/objformat.c index 877640922f..77ce1127f9 100644 --- a/usr.bin/objformat/objformat.c +++ b/usr.bin/objformat/objformat.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.bin/objformat/objformat.c,v 1.6 1998/10/24 02:01:30 jdp Exp $ - * $DragonFly: src/usr.bin/objformat/objformat.c,v 1.23 2007/08/26 08:15:50 corecode Exp $ + * $DragonFly: src/usr.bin/objformat/objformat.c,v 1.24 2007/08/26 20:40:55 corecode Exp $ */ #include @@ -83,7 +83,8 @@ static struct command commands[] = { {"size", BINUTILS2}, {"strings", BINUTILS2}, {"strip", BINUTILS2}, - {"objformat", OBJFORMAT} + {"objformat", OBJFORMAT}, + {"", -1} }; int @@ -112,7 +113,7 @@ main(int argc, char **argv) else cmd = argv[0]; - for (cmds = commands; cmds < &commands[arysize(commands)]; ++cmds) { + for (cmds = commands; cmds < &commands[arysize(commands) - 1]; ++cmds) { if (strcmp(cmd, cmds->cmd) == 0) break; } @@ -140,7 +141,7 @@ main(int argc, char **argv) case OBJFORMAT: break; default: - err(1, "unknown command type"); + errx(1, "unknown command type"); break; } } -- 2.11.4.GIT