Package: libdvdread Version: 4.1.4-1219 Severity: important Tags: patch User: debian-h...@lists.debian.org Usertags: hurd
Hello, libdvdread FTBFS on hurd-i386 due to PATH_MAX usage, which is not defined on GNU/Hurd. The attached patch fixes these problems by using dynamic buffer allocation. It can conveniently be added last in the patch series. Thanks, Svante
diff -ur libdvdread-4.1.4-1219/src/dvd_reader.c libdvdread-4.1.4-1219.modified//src/dvd_reader.c --- libdvdread-4.1.4-1219/src/dvd_reader.c 2010-07-31 02:10:28.000000000 +0200 +++ libdvdread-4.1.4-1219.modified//src/dvd_reader.c 2011-09-07 15:48:37.000000000 +0200 @@ -424,6 +424,12 @@ if( chdir( path_copy ) == -1 ) { goto DVDOpen_error; } +#ifdef __GLIBC__ + new_path = get_current_dir_name(); + if(new_path == NULL) { + goto DVDOpen_error; + } +#else new_path = malloc(PATH_MAX+1); if(!new_path) { goto DVDOpen_error; @@ -431,6 +437,7 @@ if( getcwd( new_path, PATH_MAX ) == NULL ) { goto DVDOpen_error; } +#endif retval = fchdir( cdir ); close( cdir ); cdir = -1; @@ -625,17 +632,23 @@ * or -1 on file not found. * or -2 on path not found. */ -static int findDirFile( const char *path, const char *file, char *filename ) +static int findDirFile( const char *path, const char *file, char **filename ) { DIR *dir; struct dirent *ent; + *filename = NULL; dir = opendir( path ); if( !dir ) return -2; while( ( ent = readdir( dir ) ) != NULL ) { if( !strcasecmp( ent->d_name, file ) ) { - sprintf( filename, "%s%s%s", path, + *filename = malloc( strlen( path ) + 1 + strlen( ent->d_name ) + 1 ); + if( *filename == NULL ) { + closedir(dir); + return -1; + } + sprintf( *filename, "%s%s%s", path, ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ), ent->d_name ); closedir(dir); @@ -646,9 +659,9 @@ return -1; } -static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename ) +static int findDVDFile( dvd_reader_t *dvd, const char *file, char **filename ) { - char video_path[ PATH_MAX + 1 ]; + char *video_path = NULL; const char *nodirfile; int ret; @@ -662,6 +675,8 @@ ret = findDirFile( dvd->path_root, nodirfile, filename ); if( ret < 0 ) { /* Try also with adding the path, just in case. */ + video_path = malloc( strlen( dvd->path_root ) + 10 + 1 ); + if( video_path == NULL ) return 0; sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root ); ret = findDirFile( video_path, nodirfile, filename ); if( ret < 0 ) { @@ -669,9 +684,11 @@ sprintf( video_path, "%s/video_ts/", dvd->path_root ); ret = findDirFile( video_path, nodirfile, filename ); if( ret < 0 ) { + free( video_path ); return 0; } } + free( video_path ); } return 1; @@ -682,20 +699,22 @@ */ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename ) { - char full_path[ PATH_MAX + 1 ]; + char *full_path = NULL; dvd_file_t *dvd_file; struct stat fileinfo; dvd_input_t dev; /* Get the full path of the file. */ - if( !findDVDFile( dvd, filename, full_path ) ) { + if( !findDVDFile( dvd, filename, &full_path ) ) { fprintf( stderr, "libdvdnav:DVDOpenFilePath:findDVDFile %s failed\n", filename ); + free( full_path ); return NULL; } dev = dvdinput_open( full_path ); if( !dev ) { fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvdinput_open %s failed\n", full_path ); + free( full_path ); return NULL; } @@ -703,6 +722,7 @@ if( !dvd_file ) { fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvd_file malloc failed\n" ); dvdinput_close(dev); + free( full_path ); return NULL; } dvd_file->dvd = dvd; @@ -714,6 +734,7 @@ if( stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); + free( full_path ); free( dvd_file ); return NULL; } @@ -721,6 +742,7 @@ dvd_file->title_devs[ 0 ] = dev; dvd_file->filesize = dvd_file->title_sizes[ 0 ]; + free( full_path ); return dvd_file; } @@ -776,7 +798,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) { char filename[ MAX_UDF_FILE_NAME_LEN ]; - char full_path[ PATH_MAX + 1 ]; + char *full_path = NULL; struct stat fileinfo; dvd_file_t *dvd_file; int i; @@ -799,13 +821,15 @@ } else { sprintf( filename, "VTS_%02i_0.VOB", title ); } - if( !findDVDFile( dvd, filename, full_path ) ) { + if( !findDVDFile( dvd, filename, &full_path ) ) { + free( full_path ); free( dvd_file ); return NULL; } dev = dvdinput_open( full_path ); if( dev == NULL ) { + free( full_path ); free( dvd_file ); return NULL; } @@ -813,6 +837,7 @@ if( stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); dvdinput_close(dev); + free( full_path ); free( dvd_file ); return NULL; } @@ -825,7 +850,7 @@ for( i = 0; i < TITLES_MAX; ++i ) { sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 ); - if( !findDVDFile( dvd, filename, full_path ) ) { + if( !findDVDFile( dvd, filename, &full_path ) ) { break; } @@ -840,11 +865,12 @@ dvd_file->filesize += dvd_file->title_sizes[ i ]; } if( !dvd_file->title_devs[ 0 ] ) { + free( full_path ); free( dvd_file ); return NULL; } } - + free( full_path ); return dvd_file; } @@ -966,7 +992,7 @@ int menu, dvd_stat_t *statbuf ) { char filename[ MAX_UDF_FILE_NAME_LEN ]; - char full_path[ PATH_MAX + 1 ]; + char *full_path = NULL; struct stat fileinfo; off_t tot_size; off_t parts_size[ 9 ]; @@ -978,11 +1004,13 @@ else sprintf( filename, "VTS_%02d_%d.VOB", title, menu ? 0 : 1 ); - if( !findDVDFile( dvd, filename, full_path ) ) + if( !findDVDFile( dvd, filename, &full_path ) ) + free( full_path ); return -1; if( stat( full_path, &fileinfo ) < 0 ) { fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); + free( full_path ); return -1; } @@ -994,7 +1022,7 @@ int cur; for( cur = 2; cur < 10; cur++ ) { sprintf( filename, "VTS_%02d_%d.VOB", title, cur ); - if( !findDVDFile( dvd, filename, full_path ) ) + if( !findDVDFile( dvd, filename, &full_path ) ) break; if( stat( full_path, &fileinfo ) < 0 ) { @@ -1013,6 +1041,7 @@ for( n = 0; n < nr_parts; n++ ) statbuf->parts_size[ n ] = parts_size[ n ]; + free( full_path ); return 0; } @@ -1021,7 +1050,7 @@ dvd_read_domain_t domain, dvd_stat_t *statbuf ) { char filename[ MAX_UDF_FILE_NAME_LEN ]; - char full_path[ PATH_MAX + 1 ]; + char *full_path = NULL; struct stat fileinfo; uint32_t size; @@ -1077,17 +1106,19 @@ return 0; } } else { - if( findDVDFile( dvd, filename, full_path ) ) { + if( findDVDFile( dvd, filename, &full_path ) ) { if( stat( full_path, &fileinfo ) < 0 ) fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); else { statbuf->size = fileinfo.st_size; statbuf->nr_parts = 1; statbuf->parts_size[ 0 ] = statbuf->size; + free( full_path ); return 0; } } } + free( full_path ); return -1; }