diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2015-05-04 16:32:05 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-05-04 17:54:01 +0200 |
commit | 83d3ee7fdb4e8063b163cfc1057b97cb154536a9 (patch) | |
tree | b9802bc2262b365e71717d94b4cd91a959761782 | |
parent | b1a3f4ee33a300ae446eccb024f472e54ac9361a (diff) | |
download | libssh-83d3ee7fdb4e8063b163cfc1057b97cb154536a9.tar.gz libssh-83d3ee7fdb4e8063b163cfc1057b97cb154536a9.tar.xz libssh-83d3ee7fdb4e8063b163cfc1057b97cb154536a9.zip |
string: Improve ssh_string_len() to avoid tainted variables
CID: #1278978
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | src/string.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/string.c b/src/string.c index 9002478f..ba112716 100644 --- a/src/string.c +++ b/src/string.c @@ -129,11 +129,18 @@ struct ssh_string_struct *ssh_string_from_char(const char *what) { * @return The size of the content of the string, 0 on error. */ size_t ssh_string_len(struct ssh_string_struct *s) { - if (s == NULL) { - return ntohl(0); - } + size_t size; + + if (s == NULL) { + return 0; + } + + size = ntohl(s->size); + if (size > 0 && size < UINT_MAX) { + return size; + } - return ntohl(s->size); + return 0; } /** |