diff options
author | Simon Rettberg | 2017-10-24 22:03:46 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-10-24 22:03:46 +0200 |
commit | 58e8672218b607ea0c27a32eeadd1c5ac459c840 (patch) | |
tree | 444650a3a4755813191fd52ef791672a13572aaf /src | |
parent | [SERVER] Initialize PRNG (diff) | |
download | dnbd3-58e8672218b607ea0c27a32eeadd1c5ac459c840.tar.gz dnbd3-58e8672218b607ea0c27a32eeadd1c5ac459c840.tar.xz dnbd3-58e8672218b607ea0c27a32eeadd1c5ac459c840.zip |
[FUSE] Fix type mismatch warnings
Diffstat (limited to 'src')
-rw-r--r-- | src/fuse/connection.c | 29 | ||||
-rw-r--r-- | src/fuse/connection.h | 3 | ||||
-rw-r--r-- | src/fuse/main.c | 23 |
3 files changed, 37 insertions, 18 deletions
diff --git a/src/fuse/connection.c b/src/fuse/connection.c index a3007fd..29ac2de 100644 --- a/src/fuse/connection.c +++ b/src/fuse/connection.c @@ -234,17 +234,21 @@ void connection_close() pthread_mutex_unlock( &connection.sendMutex ); } -int connection_printStats(char *buffer, const int len) +size_t connection_printStats(char *buffer, const size_t len) { int ret; - int remaining = len; + size_t remaining = len; if ( remaining > 0 ) { ret = snprintf( buffer, remaining, "Image: %s\nRevision: %d\n\nCurrent connection time: %ds\n\n", image.name, (int)image.rid, (int)( (nowMilli() - connection.startupTime) / 1000 ) ); - if ( ret > 0 ) { - remaining -= ret; - buffer += ret; + if ( ret < 0 ) { + ret = 0; } + if ( (size_t)ret >= remaining ) { + return len; + } + remaining -= ret; + buffer += ret; } int i = -1; pthread_spin_lock( &altLock ); @@ -256,12 +260,12 @@ int connection_printStats(char *buffer, const int len) } else { *buffer++ = ' '; } - ret = sock_printHost( &altservers[i].host, buffer, remaining ); - remaining -= (ret + 1); // For space or * above - buffer += ret; + const size_t addrlen = sock_printHost( &altservers[i].host, buffer, remaining ); + remaining -= (addrlen + 1); // For space or * above + buffer += addrlen; if ( remaining < 3 ) break; - int width = MAX( 35 - ret, 0 ); + int width = addrlen >= 35 ? 0 : 35 - (int)addrlen; char *unit; int value; if ( altservers[i].rtt > 5000 ) { @@ -274,6 +278,13 @@ int connection_printStats(char *buffer, const int len) } ret = snprintf( buffer, remaining, "% *d %s Unreachable: % 4d BestCount: % 4d\n", width, value, unit, altservers[i].consecutiveFails, altservers[i].bestCount ); + if ( ret < 0 ) { + ret = 0; + } + if ( (size_t)ret >= remaining ) { + remaining = 0; + break; + } remaining -= ret; buffer += ret; } diff --git a/src/fuse/connection.h b/src/fuse/connection.h index a97f2cc..37bca88 100644 --- a/src/fuse/connection.h +++ b/src/fuse/connection.h @@ -2,6 +2,7 @@ #define _CONNECTION_H_ #include "../shared/fdsignal.h" +#include <stddef.h> #include <stdbool.h> #include <stdint.h> @@ -27,6 +28,6 @@ bool connection_read(dnbd3_async_t *request); void connection_close(); -int connection_printStats(char *buffer, const int len); +size_t connection_printStats(char *buffer, const size_t len); #endif /* CONNECTION_H_ */ diff --git a/src/fuse/main.c b/src/fuse/main.c index 1759c06..35acddd 100644 --- a/src/fuse/main.c +++ b/src/fuse/main.c @@ -90,10 +90,10 @@ static int image_open(const char *path, struct fuse_file_info *fi) static int fillStatsFile(char *buf, size_t size, off_t offset) { if ( offset == 0 ) { - return connection_printStats( buf, size ); + return (int)connection_printStats( buf, size ); } char buffer[4096]; - int ret = connection_printStats( buffer, sizeof buffer ); + int ret = (int)connection_printStats( buffer, sizeof buffer ); int len = MIN( ret - (int)offset, (int)size ); if ( len == 0 ) return 0; @@ -106,14 +106,21 @@ static int fillStatsFile(char *buf, size_t size, off_t offset) { static int image_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi UNUSED) { - if ( (uint64_t)offset >= imageSize ) { - return 0; + if ( size > __INT_MAX__ ) { + // fuse docs say we MUST fill the buffer with exactly size bytes and return size, + // otherwise the buffer will we padded with zeros. Since the return value is just + // an int, we could not properly fulfill read requests > 2GB. Since there is no + // mention of a guarantee that this will never happen, better add a safety check. + // Way to go fuse. + return -EIO; } - if ( path[1] == STATS_PATH[1] ) { - return fillStatsFile(buf, size, offset); + return fillStatsFile( buf, size, offset ); + } + + if ( (uint64_t)offset >= imageSize ) { + return -EIO; } - //return -ENOENT; if ( offset + size > imageSize ) { size = imageSize - offset; @@ -125,7 +132,7 @@ static int image_read(const char *path, char *buf, size_t size, off_t offset, st if ( useDebug ) { for ( ; startBlock <= endBlock; startBlock++ ) { - logInfo.blockRequestCount[startBlock] += 1; + ++logInfo.blockRequestCount[startBlock]; } } |