浏览代码

Properly check return values of fread()

tags/v1.0
父节点
当前提交
4cb75eb337
共有 1 个文件被更改,包括 16 次插入4 次删除
  1. 16
    4
      drmdecrypt.c

+ 16
- 4
drmdecrypt.c 查看文件

@@ -70,7 +70,10 @@ int readdrmkey(char *mdbfile)
70 70
    {
71 71
       fseek(mdbfp, 8, SEEK_SET);
72 72
       for (j = 0; j < 0x10; j++){
73
-         fread(&drmkey[(j&0xc)+(3-(j&3))], sizeof(unsigned char), 1, mdbfp);
73
+         if(fread(&drmkey[(j&0xc)+(3-(j&3))], sizeof(unsigned char), 1, mdbfp) != 1){
74
+            trace(TRC_ERROR, "short read while reading DRM key");
75
+            return 1;
76
+         }
74 77
       }
75 78
       fclose(mdbfp);
76 79
 
@@ -103,7 +106,10 @@ int genoutfilename(char *outfile, char *inffile)
103 106
    if((inffp = fopen(inffile, "rb")))
104 107
    {
105 108
       fseek(inffp, 0, SEEK_SET);
106
-      fread(inf, sizeof(unsigned char), 0x200, inffp);
109
+      if(fread(inf, sizeof(unsigned char), 0x200, inffp) != 0x200){
110
+         trace(TRC_ERROR, "short read while reading inf file");
111
+         return 1;
112
+      }
107 113
       fclose(inffp);
108 114
 
109 115
       /* build base path */
@@ -364,7 +370,10 @@ resync:
364 370
 
365 371
    while(sync_find == 0 && retries-- > 0)
366 372
    {
367
-      fread(buf, sizeof(unsigned char), sizeof(buf), srffp);
373
+      if(fread(buf, sizeof(unsigned char), sizeof(buf), srffp) != sizeof(buf)){
374
+         trace(TRC_INFO, "short read while resyncing");
375
+         break;
376
+      }
368 377
 
369 378
       /* search 188byte packets starting with 0x47 */
370 379
       for(i=0; i < (sizeof(buf)-188-188); i++)
@@ -386,7 +395,10 @@ resync:
386 395
    {
387 396
       for(i=0; foffset+i < filesize; i+= 188)
388 397
       {
389
-         fread(buf, sizeof(unsigned char), 188, srffp);
398
+         if(fread(buf, sizeof(unsigned char), 188, srffp) != 188){
399
+            trace(TRC_INFO, "short read while reading stream");
400
+            break;
401
+         }
390 402
 
391 403
          if (buf[0] == 0x47)
392 404
          {

正在加载...
取消
保存