summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Freitas <miguelfreitas@users.sourceforge.net>2004-04-09 22:12:09 +0000
committerMiguel Freitas <miguelfreitas@users.sourceforge.net>2004-04-09 22:12:09 +0000
commit4ef0ea5839a70fbbd7426655a1d498cc7d0f5f90 (patch)
treed4bfbacd831f33f7b4b144f4f8ecb93d9583b1e6
parentb6ae9e904ccd4028156ffa680b07d51336b76877 (diff)
downloadxine-lib-4ef0ea5839a70fbbd7426655a1d498cc7d0f5f90.tar.gz
xine-lib-4ef0ea5839a70fbbd7426655a1d498cc7d0f5f90.tar.bz2
receiving data from network is kind of critical, we better be careful
about buffer overruns. CVS patchset: 6368 CVS date: 2004/04/09 22:12:09
-rw-r--r--src/xine-engine/io_helper.c11
-rw-r--r--src/xine-engine/io_helper.h4
2 files changed, 11 insertions, 4 deletions
diff --git a/src/xine-engine/io_helper.c b/src/xine-engine/io_helper.c
index d16267794..47038296d 100644
--- a/src/xine-engine/io_helper.c
+++ b/src/xine-engine/io_helper.c
@@ -340,17 +340,22 @@ off_t _x_io_file_write (xine_stream_t *stream, int s, char *buf, off_t todo) {
}
/*
- * read a string from socket, return size length
+ * read a string from socket, return string length (same as strlen)
+ * the string is always '\0' terminated but given buffer size is never exceeded
+ * that is, _x_io_tcp_read_line(,,,X) <= (X-1) ; X > 0
*/
int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size) {
int i = 0;
char c;
off_t r;
+ if( size <= 0 )
+ return 0;
+
while ((r = xio_rw_abort(stream, sock, XIO_TCP_READ, &c, 1)) != -1) {
if (c == '\r' || c == '\n')
break;
- if (i > size)
+ if (i+1 == size)
break;
str[i] = c;
@@ -362,5 +367,5 @@ int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size) {
str[i] = '\0';
- return (int)r;
+ return (r != -1) ? i : (int)r;
}
diff --git a/src/xine-engine/io_helper.h b/src/xine-engine/io_helper.h
index 0b1d522e3..9a174a09e 100644
--- a/src/xine-engine/io_helper.h
+++ b/src/xine-engine/io_helper.h
@@ -113,7 +113,9 @@ off_t _x_io_file_read (xine_stream_t *stream, int fd, char *buf, off_t todo);
off_t _x_io_file_write (xine_stream_t *stream, int fd, char *buf, off_t todo);
/*
- * read a string from socket, return size length
+ * read a string from socket, return string length (same as strlen)
+ * the string is always '\0' terminated but given buffer size is never exceeded
+ * that is, _x_io_tcp_read_line(,,,X) <= (X-1) ; X > 0
*/
int _x_io_tcp_read_line(xine_stream_t *stream, int sock, char *str, int size);