Skip to content

Commit

Permalink
Fixed short argument parsing bug
Browse files Browse the repository at this point in the history
- Fixed an issue where arguments shorter than the short or long prefix lengths would cause a bounds check crash.
- Closed #66.
  • Loading branch information
00JCIV00 committed Oct 23, 2024
1 parent f915352 commit 1b8067e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cova.zig
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn parseArgsCtx(
if (opt_term) continue :parseArg;
// - Short Options
if (OptionT.short_prefix) |short_pf| checkShortOpt: {
if (!(arg[0] == short_pf and arg[1] != short_pf)) break :checkShortOpt;
if (arg.len < 1 or !(arg[0] == short_pf and arg[1] != short_pf)) break :checkShortOpt;
log.debug("Parsing Short Option...", .{});
const short_opts = arg[1..];
shortOpts: for (short_opts, 0..) |short_opt, short_idx| {
Expand Down Expand Up @@ -416,7 +416,7 @@ fn parseArgsCtx(
}
// - Long Options
if (OptionT.long_prefix) |long_pf| checkLongOpt: {
if (!mem.eql(u8, arg[0..long_pf.len], long_pf)) break :checkLongOpt;
if (arg.len < long_pf.len or !mem.eql(u8, arg[0..long_pf.len], long_pf)) break :checkLongOpt;
log.debug("Parsing Long Option...", .{});
const split_idx = (mem.indexOfAny(u8, arg[long_pf.len..], OptionT.opt_val_seps) orelse arg.len - long_pf.len) + long_pf.len;
const long_opt = arg[long_pf.len..split_idx];
Expand Down

0 comments on commit 1b8067e

Please sign in to comment.