mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 17:42:17 +00:00
stream_cue: fix multiple bugs
Spelling fix. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33510 b3059339-0415-0410-9bf9-f77b7e298cf2 Simplify: remove an unnecessary loop variable. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33511 b3059339-0415-0410-9bf9-f77b7e298cf2 Add some "const". git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33512 b3059339-0415-0410-9bf9-f77b7e298cf2 Simplify NULL check. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33513 b3059339-0415-0410-9bf9-f77b7e298cf2 Avoid crash if terminating " is missing. Part of patch by Ivan Kalvachev [ikalvachev gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33514 b3059339-0415-0410-9bf9-f77b7e298cf2 Fix 0-termination being placed one byte too far. Part of patch by Ivan Kalvachev [ikalvachev gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33515 b3059339-0415-0410-9bf9-f77b7e298cf2 Ensure 0-termination even if line does not start with FILE " Part of patch by Ivan Kalvachev [ikalvachev gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33516 b3059339-0415-0410-9bf9-f77b7e298cf2 Only accept regular files as .bin files for .cue files. In particular avoids trying to use directories as .bin when e.g. we failed to extract a filename. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33517 b3059339-0415-0410-9bf9-f77b7e298cf2 Remove a duplicated open() call that could lead to a file-descriptor leak in some cases. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33518 b3059339-0415-0410-9bf9-f77b7e298cf2 Avoid possible crash if cue filename is very short. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33519 b3059339-0415-0410-9bf9-f77b7e298cf2 Simplify by using av_strlcpy. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33520 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
48fdd3d926
commit
d26f11deaf
@ -105,7 +105,7 @@ static struct cue_track_pos {
|
||||
/* number of tracks on the cd */
|
||||
static int nTracks = 0;
|
||||
|
||||
static int digits2int(char s[2], int errval) {
|
||||
static int digits2int(const char s[2], int errval) {
|
||||
uint8_t a = s[0] - '0';
|
||||
uint8_t b = s[1] - '0';
|
||||
if (a > 9 || b > 9)
|
||||
@ -169,47 +169,47 @@ static int cue_getTrackinfo(FILE *fd_cue, char *Line, tTrack *track)
|
||||
* on the arrays to have the same size, thus we need to make
|
||||
* sure the sizes are in sync.
|
||||
*/
|
||||
static int cue_find_bin (char *firstline) {
|
||||
static int cue_find_bin (const char *firstline) {
|
||||
struct stat filestat;
|
||||
const char *cur_name;
|
||||
int i,j;
|
||||
char bin_filename[256];
|
||||
char s[256];
|
||||
char t[256];
|
||||
int fd_bin;
|
||||
int i = 0;
|
||||
|
||||
/* get the filename out of that */
|
||||
/* 12345 6 */
|
||||
mp_msg (MSGT_OPEN,MSGL_INFO, "[bincue] cue_find_bin(%s)\n", firstline);
|
||||
if (strncmp(firstline, "FILE \"",6)==0)
|
||||
{
|
||||
i = 0;
|
||||
j = 0;
|
||||
while ( firstline[6 + i] != '"')
|
||||
firstline += 6;
|
||||
while ( *firstline && *firstline != '"')
|
||||
{
|
||||
bin_filename[j] = firstline[6 + i];
|
||||
bin_filename[i] = *firstline++;
|
||||
|
||||
/* if I found a path info, than delete all bevor it */
|
||||
switch (bin_filename[j])
|
||||
/* if I found a path info, then delete all before it */
|
||||
switch (bin_filename[i])
|
||||
{
|
||||
case '\\':
|
||||
j = 0;
|
||||
i = 0;
|
||||
break;
|
||||
|
||||
case '/':
|
||||
j = 0;
|
||||
i = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
bin_filename[j+1] = '\0';
|
||||
|
||||
}
|
||||
bin_filename[i] = '\0';
|
||||
|
||||
fd_bin = -1;
|
||||
for (i = 0; fd_bin == -1 && i < 6; i++) {
|
||||
if (i > 1 && strlen(cue_filename) < 3)
|
||||
break;
|
||||
switch (i) {
|
||||
case 0:
|
||||
/* now try to open that file, without path */
|
||||
@ -222,22 +222,19 @@ static int cue_find_bin (char *firstline) {
|
||||
break;
|
||||
case 2:
|
||||
/* now I would say the whole filename is shit, build our own */
|
||||
strncpy(s, cue_filename, strlen(cue_filename) - 3 );
|
||||
s[strlen(cue_filename) - 3] = '\0';
|
||||
strcat(s, "bin");
|
||||
av_strlcpy(s, cue_filename, strlen(cue_filename) - 3 );
|
||||
strcat(s, ".bin");
|
||||
cur_name = s;
|
||||
break;
|
||||
case 3:
|
||||
/* ok try it with path */
|
||||
snprintf(t, sizeof( t ), "%s/%s", bincue_path, s);
|
||||
fd_bin = open (t, O_RDONLY);
|
||||
cur_name = t;
|
||||
break;
|
||||
case 4:
|
||||
/* now I would say the whole filename is shit, build our own */
|
||||
strncpy(s, cue_filename, strlen(cue_filename) - 3 );
|
||||
s[strlen(cue_filename) - 3] = '\0';
|
||||
strcat(s, "img");
|
||||
av_strlcpy(s, cue_filename, strlen(cue_filename) - 3 );
|
||||
strcat(s, ".img");
|
||||
cur_name = s;
|
||||
break;
|
||||
case 5:
|
||||
@ -247,6 +244,10 @@ static int cue_find_bin (char *firstline) {
|
||||
break;
|
||||
}
|
||||
fd_bin = open(cur_name, O_RDONLY);
|
||||
if (fstat(fd_bin, &filestat) == -1 || !S_ISREG(filestat.st_mode)) {
|
||||
close(fd_bin);
|
||||
fd_bin = -1;
|
||||
}
|
||||
if (fd_bin == -1) {
|
||||
mp_tmsg(MSGT_OPEN,MSGL_STATUS, "[bincue] bin filename tested: %s\n",
|
||||
cur_name);
|
||||
@ -303,7 +304,7 @@ static inline int cue_mode_2_sector_size(int mode)
|
||||
}
|
||||
|
||||
|
||||
static int cue_read_cue (char *in_cue_filename)
|
||||
static int cue_read_cue (const char *in_cue_filename)
|
||||
{
|
||||
struct stat filestat;
|
||||
char sLine[256];
|
||||
@ -319,7 +320,7 @@ static int cue_read_cue (char *in_cue_filename)
|
||||
/* split the filename into a path and filename part */
|
||||
s = strdup(in_cue_filename);
|
||||
t = strrchr(s, '/');
|
||||
if (t == (char *)NULL)
|
||||
if (!t)
|
||||
t = ".";
|
||||
else {
|
||||
*t = '\0';
|
||||
|
Loading…
Reference in New Issue
Block a user