1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
=== modified file 'src/dvdbackup.c'
--- src/dvdbackup.c 2012-06-24 01:13:07 +0000
+++ src/dvdbackup.c 2013-07-04 12:06:44 +0000
@@ -2,7 +2,7 @@
* dvdbackup - tool to rip DVDs from the command line
*
* Copyright (C) 2002 Olaf Beck <olaf_sc@yahoo.com>
- * Copyright (C) 2008-2012 Benjamin Drung <benjamin.drung@gmail.com>
+ * Copyright (C) 2008-2013 Benjamin Drung <benjamin.drung@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -179,7 +179,8 @@
int vob = 1;
/* Temp filename,dirname */
- char targetname[PATH_MAX];
+ char *targetname;
+ size_t targetname_length;
/* Write buffer */
@@ -217,10 +218,18 @@
fprintf(stderr,"DVDWriteCells: vob files are %d\n", number_of_vob_files);
#endif
+ // Reserve space for "<targetdir>/<title_name>/VIDEO_TS/VTS_XX_X.VOB" and terminating "\0"
+ targetname_length = strlen(targetdir) + strlen(title_name) + 24;
+ targetname = malloc(targetname_length);
+ if (targetname == NULL) {
+ fprintf(stderr, _("Failed to allocate %zu bytes for a filename.\n"), targetname_length);
+ return 1;
+ }
+
/* Remove all old files silently if they exists */
for ( i = 0 ; i < 10 ; i++ ) {
- sprintf(targetname,"%s/%s/VIDEO_TS/VTS_%02i_%i.VOB",targetdir, title_name, title_set, i + 1);
+ snprintf(targetname, targetname_length, "%s/%s/VIDEO_TS/VTS_%02i_%i.VOB", targetdir, title_name, title_set, i + 1);
#ifdef DEBUG
fprintf(stderr,"DVDWriteCells: file is %s\n", targetname);
#endif
@@ -237,9 +246,10 @@
/* Create VTS_XX_X.VOB */
if (title_set == 0) {
fprintf(stderr,_("Do not try to copy chapters from the VMG domain; there are none.\n"));
+ free(targetname);
return(1);
} else {
- sprintf(targetname,"%s/%s/VIDEO_TS/VTS_%02i_%i.VOB",targetdir, title_name, title_set, vob);
+ snprintf(targetname, targetname_length, "%s/%s/VIDEO_TS/VTS_%02i_%i.VOB", targetdir, title_name, title_set, vob);
}
#ifdef DEBUG
@@ -248,6 +258,7 @@
if ((buffer = (unsigned char *)malloc(BUFFER_SIZE * DVD_VIDEO_LB_LEN * sizeof(unsigned char))) == NULL) {
fprintf(stderr, _("Out of memory copying %s\n"), targetname);
+ free(targetname);
return(1);
}
@@ -259,6 +270,7 @@
if ((streamout = open(targetname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) {
fprintf(stderr, _("Error creating %s\n"), targetname);
perror(PACKAGE);
+ free(targetname);
return(1);
}
@@ -271,6 +283,7 @@
fprintf(stderr, _("Failed opening TITLE VOB\n"));
free(buffer);
close(streamout);
+ free(targetname);
return(1);
}
@@ -294,6 +307,7 @@
free(buffer);
DVDCloseFile(dvd_file);
close(streamout);
+ free(targetname);
return(1);
}
if (have_read < to_read) {
@@ -303,6 +317,7 @@
fprintf(stderr, _("Error writing TITLE VOB\n"));
free(buffer);
close(streamout);
+ free(targetname);
return(1);
}
#ifdef DEBUG
@@ -321,10 +336,11 @@
close(streamout);
vob = vob + 1;
size = 0;
- sprintf(targetname,"%s/%s/VIDEO_TS/VTS_%02i_%i.VOB",targetdir, title_name, title_set, vob);
+ snprintf(targetname, targetname_length, "%s/%s/VIDEO_TS/VTS_%02i_%i.VOB", targetdir, title_name, title_set, vob);
if ((streamout = open(targetname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) {
fprintf(stderr, _("Error creating %s\n"), targetname);
perror(PACKAGE);
+ free(targetname);
return(1);
}
}
@@ -334,6 +350,7 @@
DVDCloseFile(dvd_file);
free(buffer);
close(streamout);
+ free(targetname);
return(0);
}
@@ -925,8 +942,10 @@
int i;
/* Temp filename,dirname */
- char filename[PATH_MAX] = "VIDEO_TS.VOB";
- char targetname[PATH_MAX];
+ // filename is either "VIDEO_TS.VOB" or "VTS_XX_X.VOB" and terminating "\0"
+ char filename[13] = "VIDEO_TS.VOB";
+ char *targetname;
+ size_t targetname_length;
struct stat fileinfo;
/* File Handler */
@@ -943,9 +962,10 @@
/* Return value */
int result;
+
/* create filename VIDEO_TS.VOB or VTS_XX_X.VOB */
if(title_set > 0) {
- sprintf(filename, "VTS_%02i_%i.VOB", title_set, vob);
+ sprintf(filename, "VTS_%02i_%1i.VOB", title_set, vob);
}
if (title_set_info->number_of_title_sets + 1 < title_set) {
@@ -980,7 +1000,14 @@
fprintf(stderr,_("Do not try to copy a Title VOB from the VMG domain; there are none.\n"));
return(1);
} else {
- sprintf(targetname,"%s/%s/VIDEO_TS/VTS_%02i_%i.VOB",targetdir, title_name, title_set, vob);
+ // Reserve space for "<targetdir>/<title_name>/VIDEO_TS/<filename>" and terminating "\0"
+ targetname_length = strlen(targetdir) + strlen(title_name) + strlen(filename) + 12;
+ targetname = malloc(targetname_length);
+ if (targetname == NULL) {
+ fprintf(stderr, _("Failed to allocate %zu bytes for a filename.\n"), targetname_length);
+ return 1;
+ }
+ snprintf(targetname, targetname_length, "%s/%s/VIDEO_TS/%s", targetdir, title_name, filename);
}
@@ -990,6 +1017,7 @@
tsize = title_set_info->title_set[title_set].size_vob[i];
if (tsize%DVD_VIDEO_LB_LEN != 0) {
fprintf(stderr, _("The Title VOB number %d of title set %d does not have a valid DVD size\n"), i + 1, title_set);
+ free(targetname);
return(1);
} else {
offset = offset + tsize/DVD_VIDEO_LB_LEN;
@@ -1006,11 +1034,13 @@
if (! S_ISREG(fileinfo.st_mode)) {
/* TRANSLATORS: The sentence starts with "The title file %s is not valid[...]" */
fprintf(stderr,_("The %s %s is not valid, it may be a directory.\n"), _("title file"), targetname);
+ free(targetname);
return(1);
} else {
if ((streamout = open(targetname, O_WRONLY | O_TRUNC, 0666)) == -1) {
fprintf(stderr, _("Error opening %s\n"), targetname);
perror(PACKAGE);
+ free(targetname);
return(1);
}
}
@@ -1018,6 +1048,7 @@
if ((streamout = open(targetname, O_WRONLY | O_CREAT, 0666)) == -1) {
fprintf(stderr, _("Error creating %s\n"), targetname);
perror(PACKAGE);
+ free(targetname);
return(1);
}
}
@@ -1025,6 +1056,7 @@
if ((dvd_file = DVDOpenFile(dvd, title_set, DVD_READ_TITLE_VOBS))== 0) {
fprintf(stderr, _("Failed opening TITLE VOB\n"));
close(streamout);
+ free(targetname);
return(1);
}
@@ -1032,6 +1064,7 @@
DVDCloseFile(dvd_file);
close(streamout);
+ free(targetname);
return result;
}
@@ -1039,8 +1072,10 @@
static int DVDCopyMenu(dvd_reader_t * dvd, title_set_info_t * title_set_info, int title_set, char * targetdir,char * title_name, read_error_strategy_t errorstrat) {
/* Temp filename,dirname */
- char filename[PATH_MAX] = "VIDEO_TS.VOB";
- char targetname[PATH_MAX];
+ // filename is either "VIDEO_TS.VOB" or "VTS_XX_0.VOB" and terminating "\0"
+ char filename[13] = "VIDEO_TS.VOB";
+ char *targetname;
+ size_t targetname_length;
struct stat fileinfo;
/* File Handler */
@@ -1077,8 +1112,15 @@
return(1);
}
+ // Reserve space for "<targetdir>/<title_name>/VIDEO_TS/<filename>" and terminating "\0"
+ targetname_length = strlen(targetdir) + strlen(title_name) + strlen(filename) + 12;
+ targetname = malloc(targetname_length);
+ if (targetname == NULL) {
+ fprintf(stderr, _("Failed to allocate %zu bytes for a filename.\n"), targetname_length);
+ return 1;
+ }
/* Create VIDEO_TS.VOB or VTS_XX_0.VOB */
- sprintf(targetname,"%s/%s/VIDEO_TS/%s",targetdir, title_name, filename);
+ snprintf(targetname, targetname_length, "%s/%s/VIDEO_TS/%s", targetdir, title_name, filename);
if (stat(targetname, &fileinfo) == 0) {
/* TRANSLATORS: The sentence starts with "The menu file %s exists[...]" */
@@ -1087,12 +1129,14 @@
/* TRANSLATORS: The sentence starts with "The menu file %s is not valid[...]" */
fprintf(stderr,_("The %s %s is not valid, it may be a directory.\n"), _("menu file"), targetname);
DVDCloseFile(dvd_file);
+ free(targetname);
return(1);
} else {
if ((streamout = open(targetname, O_WRONLY | O_TRUNC, 0666)) == -1) {
fprintf(stderr, _("Error opening %s\n"), targetname);
perror(PACKAGE);
DVDCloseFile(dvd_file);
+ free(targetname);
return(1);
}
}
@@ -1101,6 +1145,7 @@
fprintf(stderr, _("Error creating %s\n"), targetname);
perror(PACKAGE);
DVDCloseFile(dvd_file);
+ free(targetname);
return(1);
}
}
@@ -1113,6 +1158,7 @@
DVDCloseFile(dvd_file);
close(streamout);
+ free(targetname);
return result;
}
@@ -1120,7 +1166,9 @@
static int DVDCopyIfoBup(dvd_reader_t* dvd, title_set_info_t* title_set_info, int title_set, char* targetdir, char* title_name) {
/* Temp filename, dirname */
- char targetname_ifo[PATH_MAX], targetname_bup[PATH_MAX];
+ char *targetname_ifo;
+ char *targetname_bup;
+ size_t string_length;
struct stat fileinfo;
/* Write buffer */
@@ -1148,14 +1196,26 @@
}
}
+ // Reserve space for "<targetdir>/<title_name>/VIDEO_TS/VIDEO_TS.IFO" or
+ // "<targetdir>/<title_name>/VIDEO_TS/VTS_XX_0.IFO" and terminating "\0"
+ string_length = strlen(targetdir) + strlen(title_name) + 24;
+ targetname_ifo = malloc(string_length);
+ targetname_bup = malloc(string_length);
+ if (targetname_ifo == NULL || targetname_bup == NULL) {
+ fprintf(stderr, _("Failed to allocate %zu bytes for a filename.\n"), string_length);
+ free(targetname_ifo);
+ free(targetname_bup);
+ return 1;
+ }
+
/* Create VIDEO_TS.IFO or VTS_XX_0.IFO */
if (title_set == 0) {
- sprintf(targetname_ifo,"%s/%s/VIDEO_TS/VIDEO_TS.IFO",targetdir, title_name);
- sprintf(targetname_bup,"%s/%s/VIDEO_TS/VIDEO_TS.BUP",targetdir, title_name);
+ snprintf(targetname_ifo, string_length, "%s/%s/VIDEO_TS/VIDEO_TS.IFO", targetdir, title_name);
+ snprintf(targetname_bup, string_length, "%s/%s/VIDEO_TS/VIDEO_TS.BUP", targetdir, title_name);
} else {
- sprintf(targetname_ifo,"%s/%s/VIDEO_TS/VTS_%02i_0.IFO",targetdir, title_name, title_set);
- sprintf(targetname_bup,"%s/%s/VIDEO_TS/VTS_%02i_0.BUP",targetdir, title_name, title_set);
+ snprintf(targetname_ifo, string_length, "%s/%s/VIDEO_TS/VTS_%02i_0.IFO", targetdir, title_name, title_set);
+ snprintf(targetname_bup, string_length, "%s/%s/VIDEO_TS/VTS_%02i_0.BUP", targetdir, title_name, title_set);
}
if (stat(targetname_ifo, &fileinfo) == 0) {
@@ -1164,6 +1224,8 @@
if (! S_ISREG(fileinfo.st_mode)) {
/* TRANSLATORS: The sentence starts with "The IFO file %s is not valid[...]" */
fprintf(stderr,_("The %s %s is not valid, it may be a directory.\n"), _("IFO file"), targetname_ifo);
+ free(targetname_ifo);
+ free(targetname_bup);
return(1);
}
}
@@ -1174,6 +1236,8 @@
if (! S_ISREG(fileinfo.st_mode)) {
/* TRANSLATORS: The sentence starts with "The BUP file %s is not valid[...]" */
fprintf(stderr,_("The %s %s is not valid, it may be a directory.\n"), _("BUP file"), targetname_bup);
+ free(targetname_ifo);
+ free(targetname_bup);
return(1);
}
}
@@ -1183,6 +1247,8 @@
perror(PACKAGE);
ifoClose(ifo_file);
free(buffer);
+ free(targetname_ifo);
+ free(targetname_bup);
close(streamout_ifo);
close(streamout_bup);
return 1;
@@ -1193,6 +1259,8 @@
perror(PACKAGE);
ifoClose(ifo_file);
free(buffer);
+ free(targetname_ifo);
+ free(targetname_bup);
close(streamout_ifo);
close(streamout_bup);
return 1;
@@ -1204,6 +1272,8 @@
fprintf(stderr, _("Failed opening IFO for title set %d\n"), title_set);
ifoClose(ifo_file);
free(buffer);
+ free(targetname_ifo);
+ free(targetname_bup);
close(streamout_ifo);
close(streamout_bup);
return 1;
@@ -1215,6 +1285,8 @@
perror(PACKAGE);
ifoClose(ifo_file);
free(buffer);
+ free(targetname_ifo);
+ free(targetname_bup);
close(streamout_ifo);
close(streamout_bup);
return 1;
@@ -1226,6 +1298,8 @@
fprintf(stderr, _("Error reading IFO for title set %d\n"), title_set);
ifoClose(ifo_file);
free(buffer);
+ free(targetname_ifo);
+ free(targetname_bup);
close(streamout_ifo);
close(streamout_bup);
return 1;
@@ -1236,6 +1310,8 @@
fprintf(stderr, _("Error writing %s\n"),targetname_ifo);
ifoClose(ifo_file);
free(buffer);
+ free(targetname_ifo);
+ free(targetname_bup);
close(streamout_ifo);
close(streamout_bup);
return 1;
@@ -1245,11 +1321,15 @@
fprintf(stderr, _("Error writing %s\n"),targetname_bup);
ifoClose(ifo_file);
free(buffer);
+ free(targetname_ifo);
+ free(targetname_bup);
close(streamout_ifo);
close(streamout_bup);
return 1;
}
+ free(targetname_ifo);
+ free(targetname_bup);
return 0;
}
=== modified file 'src/main.c'
--- src/main.c 2012-06-24 01:13:07 +0000
+++ src/main.c 2013-07-04 12:06:44 +0000
@@ -2,7 +2,7 @@
* dvdbackup - tool to rip DVDs from the command line
*
* Copyright (C) 2002 Olaf Beck <olaf_sc@yahoo.com>
- * Copyright (C) 2008-2012 Benjamin Drung <benjamin.drung@gmail.com>
+ * Copyright (C) 2008-2013 Benjamin Drung <benjamin.drung@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -172,7 +172,8 @@
char* targetdir = ".";
/* Temp filename,dirname */
- char targetname[PATH_MAX];
+ char *targetname;
+ size_t targetname_length;
struct stat fileinfo;
/* The DVD main structure */
@@ -403,9 +404,15 @@
}
}
-
-
- sprintf(targetname,"%s",targetdir);
+ // Reserve space for "<targetdir>/<title_name>/VIDEO_TS" and terminating "\0"
+ targetname_length = strlen(targetdir) + strlen(title_name) + 11;
+ targetname = malloc(targetname_length);
+ if (targetname == NULL) {
+ fprintf(stderr, _("Failed to allocate %zu bytes for a filename.\n"), targetname_length);
+ DVDClose(_dvd);
+ return 1;
+ }
+ snprintf(targetname, targetname_length, "%s", targetdir);
if (stat(targetname, &fileinfo) == 0) {
if (! S_ISDIR(fileinfo.st_mode)) {
@@ -421,7 +428,7 @@
}
- sprintf(targetname,"%s/%s",targetdir, title_name);
+ snprintf(targetname, targetname_length, "%s/%s", targetdir, title_name);
if (stat(targetname, &fileinfo) == 0) {
if (! S_ISDIR(fileinfo.st_mode)) {
@@ -436,7 +443,7 @@
}
}
- sprintf(targetname,"%s/%s/VIDEO_TS",targetdir, title_name);
+ snprintf(targetname, targetname_length, "%s/%s/VIDEO_TS", targetdir, title_name);
if (stat(targetname, &fileinfo) == 0) {
if (! S_ISDIR(fileinfo.st_mode)) {
@@ -513,7 +520,7 @@
}
}
-
+ free(targetname);
DVDClose(_dvd);
exit(return_code);
}
|