mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-05 20:55:46 +03:00
tests: Fix null termination in torture_read_one_line()
CID 1393902 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -132,17 +132,18 @@ static void torture_pubkey_from_file(void **state) {
|
|||||||
SSH_STRING_FREE(pubkey);
|
SSH_STRING_FREE(pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int torture_read_one_line(const char *filename, char *buffer, size_t len) {
|
static int torture_read_one_line(const char *filename, char *buffer, size_t len)
|
||||||
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t rc;
|
size_t nmemb;
|
||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fread(buffer, len, 1, fp);
|
nmemb = fread(buffer, len - 2, 1, fp);
|
||||||
if (rc != 0 || ferror(fp)) {
|
if (nmemb != 0 || ferror(fp)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user