From: Jo Sutton Date: Wed, 24 Apr 2024 02:26:20 +0000 (+1200) Subject: ctdb: Report errors from getline() X-Git-Tag: tdb-1.4.11~929 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82224fca78c4de1f9ae8524eb14dd0478641779c;p=thirdparty%2Fsamba.git ctdb: Report errors from getline() Signed-off-by: Jo Sutton Reviewed-by: Martin Schwenke --- diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 797efc89593..5e48c1513bc 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -751,7 +751,6 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, FILE *f = NULL; int ret = 0; size_t len = 0; - ssize_t nread; if (conn_list == NULL) { return EINVAL; @@ -769,7 +768,16 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, return errno; } - while ((nread = getline(&line, &len, f)) != -1) { + for (;;) { + ssize_t nread = getline(&line, &len, f); + if (nread == -1) { + if (!feof(f)) { + /* real error */ + ret = errno; + } + break; + } + if ((nread > 0) && (line[nread-1] == '\n')) { line[nread-1] = '\0'; }