diff options
author | Max Kellermann <max@duempel.org> | 2008-03-26 10:38:07 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-03-26 10:38:07 +0000 |
commit | 27f12c173d57d09d095d0e5ecfeb18acf5d2434a (patch) | |
tree | a1016cf4f069f0ab804f3023c87eb494c45dfed2 /src/interface.c | |
parent | 0692f6cd0ab12e921d1897de215fb42d6dc79a7c (diff) |
use size_t
When dealing with in-memory lengths, the standard type "size_t" should
be used. Missing one can be quite dangerous, because an attacker
could provoke an integer under-/overflow, which may provide an attack
vector.
git-svn-id: https://svn.musicpd.org/mpd/trunk@7205 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/interface.c')
-rw-r--r-- | src/interface.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/interface.c b/src/interface.c index 9a79f102e..029025cbf 100644 --- a/src/interface.c +++ b/src/interface.c @@ -59,26 +59,26 @@ static struct strnode *list_cache_tail; typedef struct _Interface { char buffer[INTERFACE_MAX_BUFFER_LENGTH]; - int bufferLength; - int bufferPos; + size_t bufferLength; + size_t bufferPos; int fd; /* file descriptor */ int permission; time_t lastTime; struct strnode *cmd_list; /* for when in list mode */ struct strnode *cmd_list_tail; /* for when in list mode */ int cmd_list_OK; /* print OK after each command execution */ - int cmd_list_size; /* mem cmd_list consumes */ + size_t cmd_list_size; /* mem cmd_list consumes */ int cmd_list_dup; /* has the cmd_list been copied to private space? */ struct sllnode *deferred_send; /* for output if client is slow */ - int deferred_bytes; /* mem deferred_send consumes */ + size_t deferred_bytes; /* mem deferred_send consumes */ int expired; /* set whether this interface should be closed on next check of old interfaces */ int num; /* interface number */ char *send_buf; - int send_buf_used; /* bytes used this instance */ - int send_buf_size; /* bytes usable this instance */ - int send_buf_alloc; /* bytes actually allocated */ + size_t send_buf_used; /* bytes used this instance */ + size_t send_buf_size; /* bytes usable this instance */ + size_t send_buf_alloc; /* bytes actually allocated */ } Interface; static Interface *interfaces; @@ -88,7 +88,7 @@ static void flushInterfaceBuffer(Interface * interface); static void printInterfaceOutBuffer(Interface * interface); #ifdef SO_SNDBUF -static int get_default_snd_buf_size(Interface * interface) +static size_t get_default_snd_buf_size(Interface * interface) { int new_size; socklen_t sockOptLen = sizeof(int); @@ -99,12 +99,12 @@ static int get_default_snd_buf_size(Interface * interface) return INTERFACE_DEFAULT_OUT_BUFFER_SIZE; } if (new_size > 0) - return new_size; + return (size_t)new_size; DEBUG("sockets send buffer size is not positive\n"); return INTERFACE_DEFAULT_OUT_BUFFER_SIZE; } #else /* !SO_SNDBUF */ -static int get_default_snd_buf_size(Interface * interface) +static size_t get_default_snd_buf_size(Interface * interface) { return INTERFACE_DEFAULT_OUT_BUFFER_SIZE; } @@ -112,7 +112,7 @@ static int get_default_snd_buf_size(Interface * interface) static void set_send_buf_size(Interface * interface) { - int new_size = get_default_snd_buf_size(interface); + size_t new_size = get_default_snd_buf_size(interface); if (interface->send_buf_size != new_size) { interface->send_buf_size = new_size; /* don't resize to get smaller, only bigger */ @@ -313,12 +313,12 @@ static int processLineOfInput(Interface * interface) if (interface->cmd_list_size > interface_max_command_list_size) { ERROR("interface %i: command " - "list size (%i) is " + "list size (%lu) is " "larger than the max " - "(%li)\n", + "(%lu)\n", interface->num, - interface->cmd_list_size, - (long)interface_max_command_list_size); + (unsigned long)interface->cmd_list_size, + (unsigned long)interface_max_command_list_size); closeInterface(interface); ret = COMMAND_RETURN_CLOSE; } else @@ -642,14 +642,14 @@ void closeOldInterfaces(void) static void flushInterfaceBuffer(Interface * interface) { struct sllnode *buf; - int ret = 0; + ssize_t ret = 0; buf = interface->deferred_send; while (buf) { ret = write(interface->fd, buf->data, buf->size); if (ret < 0) break; - else if (ret < buf->size) { + else if ((size_t)ret < buf->size) { interface->deferred_bytes -= ret; buf->data = (char *)buf->data + ret; buf->size -= ret; @@ -665,8 +665,8 @@ static void flushInterfaceBuffer(Interface * interface) } if (!interface->deferred_send) { - DEBUG("interface %i: buffer empty %i\n", interface->num, - interface->deferred_bytes); + DEBUG("interface %i: buffer empty %lu\n", interface->num, + (unsigned long)interface->deferred_bytes); assert(interface->deferred_bytes == 0); } else if (ret < 0 && errno != EAGAIN && errno != EINTR) { /* cause interface to close */ @@ -684,10 +684,10 @@ static void flushInterfaceBuffer(Interface * interface) } } -int interfacePrintWithFD(int fd, char *buffer, int buflen) +int interfacePrintWithFD(int fd, char *buffer, size_t buflen) { static int i; - int copylen; + size_t copylen; Interface *interface; assert(fd >= 0); @@ -709,7 +709,7 @@ int interfacePrintWithFD(int fd, char *buffer, int buflen) interface = interfaces + i; while (buflen > 0 && !interface->expired) { - int left = interface->send_buf_size - interface->send_buf_used; + size_t left = interface->send_buf_size - interface->send_buf_used; copylen = buflen > left ? left : buflen; memcpy(interface->send_buf + interface->send_buf_used, buffer, copylen); @@ -725,7 +725,7 @@ int interfacePrintWithFD(int fd, char *buffer, int buflen) static void printInterfaceOutBuffer(Interface * interface) { - int ret; + ssize_t ret; struct sllnode *buf; if (interface->fd < 0 || interface->expired || @@ -770,7 +770,7 @@ static void printInterfaceOutBuffer(Interface * interface) interface->expired = 1; return; } - } else if (ret < interface->send_buf_used) { + } else if ((size_t)ret < interface->send_buf_used) { interface->deferred_send = new_sllnode(interface->send_buf + ret, interface->send_buf_used - ret); |