crashes with old recordings without info file

Message ID 4D984A84.10905@pilppa.org
State New
Headers

Commit Message

Mika Laitio April 3, 2011, 10:23 a.m. UTC
  I have some old recordings made on 2005 which does not have info file. 
This caused vdr 1.7.17 to crash because
in tools.c line 1194 there is no check whether the file parameter passed 
is NULL or not. Real cause for the crash is in the vdrrip plugins which
should handle the case where the info file does not exist on 
setLengthVDR method on movie.c.
Anyway, it's propably good idea also to has the NULL check's in vdr's 
own code. Patches attached for tools.c and recording.c.

#0  0x00007ffff640e8ff in getdelim () from /lib64/libc.so.6
#1  0x00000000004fcd48 in getline (this=0x7fffffffde30, f=0x0) at 
/usr/include/bits/stdio.h:118
#2  cReadLine::Read (this=0x7fffffffde30, f=0x0) at tools.c:1194
#3  0x00000000004cc383 in cRecordingInfo::Read (this=0xc29bc0, f=0x0) at 
recording.c:419
#4  0x00007fffef0397a0 in cMovie::setLengthVDR() () from 
./PLUGINS/lib/libvdr-vdrrip.so.1.7.17
#5  0x00007fffef03af00 in cMovie::cMovie(char const*, char const*) () 
from ./PLUGINS/lib/libvdr-vdrrip.so.1.7.17
#6  0x00007fffef0367d7 in cMenuVdrripMovie::cMenuVdrripMovie(char 
const*, char const*) () from ./PLUGINS/lib/libvdr-vdrrip.so.1.7.17
#7  0x00007fffef03807d in cMenuVdrripEncode::ProcessKey(eKeys) () from 
./PLUGINS/lib/libvdr-vdrrip.so.1.7.17

[lamikr@tinka Prisma:_Einstein_ja_kaiken_teoria]$ ls -la 
2005-04-21.20\:58.50.99.rec/
total 1338080
drwxr-xr-x 2 76 76       4096 2008-05-17 17:48 ./
drwxr-xr-x 3 76 76       4096 2008-05-17 17:46 ../
-rw-r--r-- 1 76 76 1369418800 2008-05-17 17:48 001.vdr
-rw-r--r-- 1 76 76     727968 2008-05-17 17:48 index.vdr
-rw-r--r-- 1 76 76          4 2008-05-17 17:48 resume.vdr
-rw-r--r-- 1 76 76        441 2008-05-17 17:48 summary.vdr
>From ef2f4122b44abbc4cae7876bb8566ed95151cdf5 Mon Sep 17 00:00:00 2001
From: Mika Laitio <lamikr@pilppa.org>
Date: Sun, 3 Apr 2011 13:06:55 +0300
Subject: [PATCH 1/2] NULL pointer check to cReadline.read in tools.c

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
---
 tools.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)
  

Comments

Klaus Schmidinger April 3, 2011, 11:13 a.m. UTC | #1
On 03.04.2011 12:23, Mika Laitio wrote:
> I have some old recordings made on 2005 which does not have info file. This caused vdr 1.7.17 to crash because
> in tools.c line 1194 there is no check whether the file parameter passed is NULL or not. Real cause for the crash is in the vdrrip plugins which
> should handle the case where the info file does not exist on setLengthVDR method on movie.c.
> Anyway, it's propably good idea also to has the NULL check's in vdr's own code. Patches attached for tools.c and recording.c.

I wonder who is actually calling cRecordingInfo::Read(FILE *f) with
a NULL pointer? In VDR's own code all calls to that function are
made sure to get a non-NULL pointer:


bool cRecordingInfo::Read(void)
{
   bool Result = false;
   if (fileName) {
      FILE *f = fopen(fileName, "r");
      if (f) {
         if (Read(f))


cRecording::cRecording(const char *FileName)
{
   ...
      FILE *f = fopen(InfoFileName, "r");
      if (f) {
         if (!info->Read(f))


Since it doesn't make any sense to call cRecordingInfo::Read(FILE *f)
from outside cRecordingInfo, I made that function private now.
This may break some plugin, but that should have called
cRecordingInfo::Read(void), anyway.

Klaus
  
Mika Laitio April 3, 2011, 12:26 p.m. UTC | #2
I wonder who is actually calling cRecordingInfo::Read(FILE *f) with
> a NULL pointer? In VDR's own code all calls to that function are
> made sure to get a non-NULL pointer:

Yes, the real reason is in the vdrrip plugin that I cloned from
http://projects.vdr-developer.org/git/

It has this kind of code which always assumes that info file always exist.

void cMovie::setLengthVDR() {
         char *infoFile = NULL;
         asprintf(&infoFile, "%s%s", Dir, OldRecording ? "/info.vdr" : 
"/info");
         dsyslog ("[vdrrip] reading recording info %s ",infoFile);
         cRecordingInfo *crec = new cRecordingInfo(Dir);
         FILE *f = fopen(infoFile, "r");
         if (crec->Read(f)) {

I just thought that it would be good to fix that in vdr code also.
But I think putting the metod now private will also quarantee NULL 
pointer check :-)

Mika
  

Patch

diff --git a/tools.c b/tools.c
index d03595e..c09a9b0 100644
--- a/tools.c
+++ b/tools.c
@@ -1191,18 +1191,20 @@  cReadLine::~cReadLine()
 
 char *cReadLine::Read(FILE *f)
 {
-  int n = getline(&buffer, &size, f);
-  if (n > 0) {
-     n--;
-     if (buffer[n] == '\n') {
-        buffer[n] = 0;
-        if (n > 0) {
-           n--;
-           if (buffer[n] == '\r')
-              buffer[n] = 0;
+  if (f != NULL) {
+     int n = getline(&buffer, &size, f);
+     if (n > 0) {
+        n--;
+        if (buffer[n] == '\n') {
+           buffer[n] = 0;
+           if (n > 0) {
+              n--;
+              if (buffer[n] == '\r')
+                 buffer[n] = 0;
+              }
            }
+        return buffer;
         }
-     return buffer;
      }
   return NULL;
 }