
From: Marek Behún marek.behun@nic.cz
Copy the value of the found variable into given buffer with strncpy().
Signed-off-by: Marek Behún marek.behun@nic.cz --- cmd/nvedit.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 412918a000..51b9e4ffa4 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -746,18 +746,13 @@ int env_get_f(const char *name, char *buf, unsigned len) continue;
/* found; copy out */ - for (n = 0; n < len; ++n, ++buf) { - *buf = env[val++]; - if (*buf == '\0') - return n; + n = strncpy(buf, &env[val], len) - buf; + if (len && n == len) { + buf[len - 1] = '\0'; + printf("env_buf [%u bytes] too small for value of "%s"\n", + len, name); }
- if (n) - *--buf = '\0'; - - printf("env_buf [%u bytes] too small for value of "%s"\n", - len, name); - return n; }