mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 12:20:42 +09:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user