Mercurial > mplayer.hg
annotate stream/stream_vcd.c @ 22188:b9fa8b0ddab9
strncat() misuses, may have been exploitable.
Reported by Sascha Sommer.
author | rtogni |
---|---|
date | Sun, 11 Feb 2007 18:00:06 +0000 |
parents | a8cd73869242 |
children | 72fbf66a9429 |
rev | line source |
---|---|
9886 | 1 |
2 #include "config.h" | |
3 | |
4 #include "mp_msg.h" | |
5 #include "stream.h" | |
6 #include "help_mp.h" | |
17012 | 7 #include "m_option.h" |
8 #include "m_struct.h" | |
9886 | 9 |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9886
diff
changeset
|
10 #include <fcntl.h> |
9886 | 11 #include <stdlib.h> |
12 #include <unistd.h> | |
13 #include <sys/ioctl.h> | |
14 #include <errno.h> | |
15 | |
21848 | 16 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
9886 | 17 #include <sys/cdrio.h> |
18 #include "vcd_read_fbsd.h" | |
12797
b2419eef04da
OpenBSD portability patches from the OpenBSD ports tree
diego
parents:
10591
diff
changeset
|
19 #elif defined(__NetBSD__) || defined (__OpenBSD__) |
13678 | 20 #include "vcd_read_nbsd.h" |
13681
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
21 #elif defined(SYS_DARWIN) |
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
22 #include "vcd_read_darwin.h" |
9886 | 23 #else |
24 #include "vcd_read.h" | |
25 #endif | |
26 | |
21926
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
27 #include "libmpdemux/demuxer.h" |
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
28 |
10591 | 29 extern char *cdrom_device; |
30 | |
9886 | 31 static struct stream_priv_s { |
32 int track; | |
33 char* device; | |
34 } stream_priv_dflts = { | |
35 1, | |
10591 | 36 NULL |
9886 | 37 }; |
38 | |
39 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
40 /// URL definition | |
41 static m_option_t stream_opts_fields[] = { | |
42 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
43 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
44 /// For url parsing | |
45 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
46 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
47 { NULL, NULL, 0, 0, 0, 0, NULL } | |
48 }; | |
49 static struct m_struct_st stream_opts = { | |
50 "vcd", | |
51 sizeof(struct stream_priv_s), | |
52 &stream_priv_dflts, | |
53 stream_opts_fields | |
54 }; | |
55 | |
56 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
15912 | 57 if(s->pos > s->end_pos) /// don't past end of current track |
58 return 0; | |
9886 | 59 return vcd_read(s->priv,buffer); |
60 } | |
61 | |
62 static int seek(stream_t *s,off_t newpos) { | |
63 s->pos = newpos; | |
64 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA); | |
65 return 1; | |
66 } | |
67 | |
68 static void close_s(stream_t *stream) { | |
69 free(stream->priv); | |
70 } | |
71 | |
72 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
73 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
74 int ret,ret2,f; | |
75 mp_vcd_priv_t* vcd; | |
21848 | 76 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 77 int bsize = VCD_SECTOR_SIZE; |
78 #endif | |
79 | |
80 if(mode != STREAM_READ) { | |
81 m_struct_free(&stream_opts,opts); | |
82 return STREAM_UNSUPORTED; | |
83 } | |
84 | |
10591 | 85 if (!p->device) { |
86 if(cdrom_device) | |
87 p->device = strdup(cdrom_device); | |
88 else | |
89 p->device = strdup(DEFAULT_CDROM_DEVICE); | |
90 } | |
91 | |
9886 | 92 f=open(p->device,O_RDONLY); |
93 if(f<0){ | |
94 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device); | |
95 m_struct_free(&stream_opts,opts); | |
96 return STREAM_ERROR; | |
97 } | |
98 | |
99 vcd = vcd_read_toc(f); | |
100 if(!vcd) { | |
101 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n"); | |
102 close(f); | |
103 m_struct_free(&stream_opts,opts); | |
104 return STREAM_ERROR; | |
105 } | |
106 ret2=vcd_get_track_end(vcd,p->track); | |
107 if(ret2<0){ | |
108 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n"); | |
109 close(f); | |
110 free(vcd); | |
111 m_struct_free(&stream_opts,opts); | |
112 return STREAM_ERROR; | |
113 } | |
114 ret=vcd_seek_to_track(vcd,p->track); | |
115 if(ret<0){ | |
116 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n"); | |
117 close(f); | |
118 free(vcd); | |
119 m_struct_free(&stream_opts,opts); | |
120 return STREAM_ERROR; | |
121 } | |
122 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); | |
123 | |
21848 | 124 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 125 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { |
126 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE"); | |
127 } | |
128 #endif | |
129 | |
130 stream->fd = f; | |
131 stream->type = STREAMTYPE_VCD; | |
132 stream->sector_size = VCD_SECTOR_DATA; | |
133 stream->start_pos=ret; | |
134 stream->end_pos=ret2; | |
135 stream->priv = vcd; | |
136 | |
137 stream->fill_buffer = fill_buffer; | |
138 stream->seek = seek; | |
139 stream->close = close_s; | |
21926
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
140 *file_format = DEMUXER_TYPE_MPEG_PS; |
9886 | 141 |
142 m_struct_free(&stream_opts,opts); | |
143 return STREAM_OK; | |
144 } | |
145 | |
146 stream_info_t stream_info_vcd = { | |
147 "Video CD", | |
148 "vcd", | |
149 "Albeu", | |
150 "based on the code from ???", | |
151 open_s, | |
152 { "vcd", NULL }, | |
153 &stream_opts, | |
154 1 // Urls are an option string | |
155 }; |