mirror of https://github.com/mpv-player/mpv
stream_ftp: cleanups
stream ftp: Pass full buffer size to snprintf Previously the buffer size was always passed as one less than the underlying buffer's size. This is not using the underlying buffer to its full potential according to the C99 standard. The last byte of the buffers were never used. No vulnerabilities should have been caused by this mistake because the strings stored in the buffers were zero terminated at all times. Neither were out-of-array writes nor reads possible. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35488 b3059339-0415-0410-9bf9-f77b7e298cf2 stream ftp: open_f: Mark parameter file_format unused We have nothing to say about it, so we do not set *file_format. No need for compilers to emit a warning about it. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35489 b3059339-0415-0410-9bf9-f77b7e298cf2 stream ftp: Set type to STREAMTYPE_STREAM Previously this was not set at all from within the stream_ftp module. This caused the run-time warning message "Streams need a type!". The actual behaviour should not be affected by this change. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35490 b3059339-0415-0410-9bf9-f77b7e298cf2 stream ftp: Use C99 designated initializers Simplify the initialization of the stream private struct's defaults. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35491 b3059339-0415-0410-9bf9-f77b7e298cf2 stream ftp: Remove unneeded cast At worst these kind of casts can hide real errors. As it is, it is just not needed at all, thus remove it. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@35492 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
77eac2ec34
commit
1e9f37072b
|
@ -54,17 +54,10 @@ static struct stream_priv_s {
|
|||
char *buf;
|
||||
char *cmd_buf;
|
||||
} stream_priv_dflts = {
|
||||
"anonymous","no@spam",
|
||||
NULL,
|
||||
21,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
-1,
|
||||
0,0,
|
||||
NULL,
|
||||
NULL,
|
||||
.user = "anonymous",
|
||||
.pass = "no@spam",
|
||||
.port = 21,
|
||||
.handle = -1,
|
||||
};
|
||||
|
||||
#define CMD_BUFSIZE 8192
|
||||
|
@ -281,7 +274,7 @@ static int FtpOpenPort(struct stream_priv_s* p) {
|
|||
|
||||
sscanf(par+1,"%u,%u,%u,%u,%u,%u",&num[0],&num[1],&num[2],
|
||||
&num[3],&num[4],&num[5]);
|
||||
snprintf(str,127,"%d.%d.%d.%d",num[0],num[1],num[2],num[3]);
|
||||
snprintf(str,sizeof(str),"%d.%d.%d.%d",num[0],num[1],num[2],num[3]);
|
||||
fd = connect2Server(str,(num[4]<<8)+num[5],0);
|
||||
|
||||
if(fd < 0)
|
||||
|
@ -301,7 +294,7 @@ static int FtpOpenData(stream_t* s,int64_t newpos) {
|
|||
if(s->fd < 0) return 0;
|
||||
|
||||
if(newpos > 0) {
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE - 1,"REST %"PRId64, (int64_t)newpos);
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE,"REST %"PRId64, (int64_t)newpos);
|
||||
|
||||
resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
|
||||
if(resp != 3) {
|
||||
|
@ -311,7 +304,7 @@ static int FtpOpenData(stream_t* s,int64_t newpos) {
|
|||
}
|
||||
|
||||
// Get the file
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE - 1,"RETR %s",p->filename);
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE,"RETR %s",p->filename);
|
||||
resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
|
||||
|
||||
if(resp != 1) {
|
||||
|
@ -417,10 +410,10 @@ static void close_f(stream_t *s) {
|
|||
|
||||
|
||||
|
||||
static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
|
||||
static int open_f(stream_t *stream,int mode, void* opts, av_unused int* file_format) {
|
||||
int resp;
|
||||
int64_t len = 0;
|
||||
struct stream_priv_s* p = (struct stream_priv_s*)opts;
|
||||
struct stream_priv_s* p = opts;
|
||||
char rsp_txt[256];
|
||||
|
||||
if(mode != STREAM_READ) {
|
||||
|
@ -463,12 +456,12 @@ static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
|
|||
}
|
||||
|
||||
// Login
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE - 1,"USER %s",p->user);
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE,"USER %s",p->user);
|
||||
resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
|
||||
|
||||
// password needed
|
||||
if(resp == 3) {
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE - 1,"PASS %s",p->pass);
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE,"PASS %s",p->pass);
|
||||
resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
|
||||
if(resp != 2) {
|
||||
mp_msg(MSGT_OPEN,MSGL_ERR, "[ftp] command '%s' failed: %s\n",p->cmd_buf,rsp_txt);
|
||||
|
@ -490,7 +483,7 @@ static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
|
|||
}
|
||||
|
||||
// Get the filesize
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE - 1,"SIZE %s",p->filename);
|
||||
snprintf(p->cmd_buf,CMD_BUFSIZE,"SIZE %s",p->filename);
|
||||
resp = FtpSendCmd(p->cmd_buf,p,rsp_txt);
|
||||
if(resp != 2) {
|
||||
mp_msg(MSGT_OPEN,MSGL_WARN, "[ftp] command '%s' failed: %s\n",p->cmd_buf,rsp_txt);
|
||||
|
@ -512,6 +505,7 @@ static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
|
|||
stream->priv = p;
|
||||
stream->fill_buffer = fill_buffer;
|
||||
stream->close = close_f;
|
||||
stream->type = STREAMTYPE_STREAM;
|
||||
|
||||
return STREAM_OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue