From: Jaroslav Kysela Date: Mon, 14 Sep 2015 18:39:47 +0000 (+0200) Subject: DVR: fix and improve the endless loop check in pvr_generate_filename, fixes #3077 X-Git-Tag: v4.2.1~2127 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a146bbab8efbd8f39c45c54fc9e2754d3d0b95d3;p=thirdparty%2Ftvheadend.git DVR: fix and improve the endless loop check in pvr_generate_filename, fixes #3077 --- diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index 0a2df9ec3..719b2db2d 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -532,6 +532,7 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss) char path[PATH_MAX]; char ptmp[PATH_MAX]; char number[16]; + char *lastpath = NULL; int tally = 0; struct stat st; char *s, *x, *fmtstr, *dirsep; @@ -661,25 +662,25 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss) htsstr_substitute(filename + j, ptmp, sizeof(ptmp), '$', dvr_subs_tally, number); s = cleanup_filename(cfg, ptmp); - if (s == NULL) + if (s == NULL) { + free(lastpath); return -1; + } /* Construct the final filename */ memcpy(path, filename, j); path[j] = '\0'; htsstr_unescape_to(s, path + j, sizeof(path) - j); + free(s); - if (tally > 0) { - htsstr_unescape_to(filename + j, ptmp, sizeof(ptmp)); - if (strcmp(ptmp, s) == 0) { - free(s); + if (lastpath) { + if (strcmp(path, lastpath) == 0) { + free(lastpath); tvherror("dvr", "unable to create unique name (missing $n in format string?)"); return -1; } } - free(s); - if(stat(path, &st) == -1) { tvhlog(LOG_DEBUG, "dvr", "File \"%s\" -- %s -- Using for recording", path, strerror(errno)); @@ -689,9 +690,12 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss) tvhlog(LOG_DEBUG, "dvr", "Overwrite protection, file \"%s\" exists", path); + free(lastpath); + lastpath = strdup(path); tally++; } + free(lastpath); if (de->de_files == NULL) de->de_files = htsmsg_create_list(); m = htsmsg_create_map();