From: Todd C. Miller Date: Wed, 4 May 2016 22:59:04 +0000 (-0600) Subject: In fill_args(), replace loop that increments arg_size() with X-Git-Tag: SUDO_1_8_17^2~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5725acd1c401ec45fc8f999e4b71b9eed50758d2;p=sudo In fill_args(), replace loop that increments arg_size() with a simple add and mask. Should prevent a false positive from Coverity CID 104094. --- diff --git a/plugins/sudoers/toke.h b/plugins/sudoers/toke.h index c6a2db579..5b13e6710 100644 --- a/plugins/sudoers/toke.h +++ b/plugins/sudoers/toke.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2013 Todd C. Miller + * Copyright (c) 2011-2013, 2015-2016 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -31,9 +31,6 @@ extern int (*trace_print)(const char *msg); #define fill(a, b) fill_txt(a, b, 0) -/* realloc() to size + COMMANDARGINC to make room for command args */ -#define COMMANDARGINC 64 - #define LEXTRACE(msg) do { \ if (trace_print != NULL) \ (*trace_print)(msg); \ diff --git a/plugins/sudoers/toke_util.c b/plugins/sudoers/toke_util.c index a8989459a..be46782f9 100644 --- a/plugins/sudoers/toke_util.c +++ b/plugins/sudoers/toke_util.c @@ -138,9 +138,8 @@ fill_args(const char *s, size_t len, int addspace) new_len = arg_len + len + addspace; if (new_len >= arg_size) { - /* Allocate more space than we need for subsequent args */ - while (new_len >= (arg_size += COMMANDARGINC)) - continue; + /* Allocate in increments of 128 bytes to avoid excessive realloc(). */ + arg_size = (new_len + 127) & ~127; p = realloc(sudoerslval.command.args, arg_size); if (p == NULL) {