aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests/torture_pki.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2014-08-15 10:32:57 +0200
committerAndreas Schneider <asn@cryptomilk.org>2014-08-15 12:29:23 +0200
commit8b7627efd55d84d4f23bbf437f5ae91512ce310b (patch)
treebe2f6f9164db5b0232c4d50066045e9020e1cb28 /tests/unittests/torture_pki.c
parent662217f4097b2efbde5f7f9a190ad1b031f35716 (diff)
downloadlibssh-8b7627efd55d84d4f23bbf437f5ae91512ce310b.tar.gz
libssh-8b7627efd55d84d4f23bbf437f5ae91512ce310b.tar.xz
libssh-8b7627efd55d84d4f23bbf437f5ae91512ce310b.zip
tests: Make sure we null terminate the buffer.
CID: 1230359 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
Diffstat (limited to 'tests/unittests/torture_pki.c')
-rw-r--r--tests/unittests/torture_pki.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c
index b2cd088f..32c73819 100644
--- a/tests/unittests/torture_pki.c
+++ b/tests/unittests/torture_pki.c
@@ -279,18 +279,19 @@ static void write_file(const char *filename, const char *data){
static int torture_read_one_line(const char *filename, char *buffer, size_t len) {
FILE *fp;
- size_t rc;
+ size_t nmemb;
fp = fopen(filename, "r");
if (fp == NULL) {
return -1;
}
- rc = fread(buffer, len, 1, fp);
- if (rc != 0 || ferror(fp)) {
+ nmemb = fread(buffer, len - 1, 1, fp);
+ if (nmemb != 0 || ferror(fp)) {
fclose(fp);
return -1;
}
+ buffer[len] = '\0';
fclose(fp);