All of lore.kernel.org
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] Fix getcwd03 testcase by zeroing target buffer for readlink()
Date: Thu, 4 May 2017 20:23:46 +0200	[thread overview]
Message-ID: <20170504182346.GA4959@ls3530.fritz.box> (raw)

According to the man(2) page of readlink(), a null byte is not appended to the
target buffer. So applications need to make sure that the target buffer is
zero-initialized, otherwise random bytes at the end of the returned string may
exist. 

This patch zero-initializes the on-stack char array "link" and thus fixes the
testcase failure of getcwd03 on the hppa/parisc architecture (and maybe others).

Signed-off-by: Helge Deller <deller@gmx.de>

--
 testcases/kernel/syscalls/getcwd/getcwd03.c |    1 +
 1 file changed, 1 insertion(+)


diff --git a/testcases/kernel/syscalls/getcwd/getcwd03.c b/testcases/kernel/syscalls/getcwd/getcwd03.c
index 4f8f872cf..ec1cacea9 100644
--- a/testcases/kernel/syscalls/getcwd/getcwd03.c
+++ b/testcases/kernel/syscalls/getcwd/getcwd03.c
@@ -74,6 +74,7 @@ static void verify_getcwd(void)
 	}
 
 	SAFE_CHDIR("..");
+	memset(link, 0, sizeof(link));
 	SAFE_READLINK(dir_link, link, sizeof(link));
 
 	if (strcmp(link, SAFE_BASENAME(res1))) {

             reply	other threads:[~2017-05-04 18:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-04 18:23 Helge Deller [this message]
2017-05-05  9:34 ` [LTP] [PATCH] Fix getcwd03 testcase by zeroing target buffer for readlink() Cyril Hrubis
2017-05-06  7:00   ` Helge Deller
2017-05-09  9:08     ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170504182346.GA4959@ls3530.fritz.box \
    --to=deller@gmx.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.