From effbb7219237e3c0615396b9a75449bf3b228e8e Mon Sep 17 00:00:00 2001 From: Peter Stuge Date: Wed, 1 Feb 2012 10:56:42 +0100 Subject: [PATCH] example/subsystem_netconf.c: Return error when read buffer is too small Also remove a little redundancy in the read loop condition. --- example/subsystem_netconf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/example/subsystem_netconf.c b/example/subsystem_netconf.c index f960c91..708113b 100644 --- a/example/subsystem_netconf.c +++ b/example/subsystem_netconf.c @@ -61,7 +61,8 @@ static int netconf_write(LIBSSH2_CHANNEL *channel, const char *buf, size_t len) static int netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag, char *buf, size_t buflen) { - ssize_t len, rd = 0; + ssize_t len; + size_t rd = 0; char *endreply = NULL, *specialsequence = NULL; memset(buf, 0, buflen); @@ -85,7 +86,12 @@ static int netconf_read_until(LIBSSH2_CHANNEL *channel, const char *endtag, if (endreply) specialsequence = strstr(endreply, "]]>]]>"); - } while (!endreply || !specialsequence); + } while (!specialsequence && rd < buflen); + + if (!specialsequence) { + fprintf(stderr, "%s: ]]>]]> not found! read buffer too small?\n", __func__); + return -1; + } /* discard the special sequence so that only XML is returned */ rd = specialsequence - buf;