Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/installer/mac/third_party/bsdiff/goobspatch.c

Issue 287483002: goobspatch: Improve sanity checks for invalid patches. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/mac/third_party/bsdiff/README.chromium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*- 1 /*-
2 * Copyright 2003-2005 Colin Percival 2 * Copyright 2003-2005 Colin Percival
3 * All rights reserved 3 * All rights reserved
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted providing that the following conditions 6 * modification, are permitted providing that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 oldpos=0;newpos=0; 464 oldpos=0;newpos=0;
465 while(newpos<newsize) { 465 while(newpos<newsize) {
466 /* Read control data */ 466 /* Read control data */
467 for(i=0;i<=2;i++) { 467 for(i=0;i<=2;i++) {
468 cfread(&cf, buf, 8); 468 cfread(&cf, buf, 8);
469 ctrl[i]=offtin(buf); 469 ctrl[i]=offtin(buf);
470 }; 470 };
471 471
472 /* Sanity-check */ 472 /* Sanity-check */
473 if((ctrl[0]<0) || (ctrl[1]<0))
474 errx(1,"corrupt patch (diff): negative chunk size");
475
476 /* Sanity-check */
473 if(newpos+ctrl[0]>newsize) 477 if(newpos+ctrl[0]>newsize)
474 errx(1,"corrupt patch (diff): overrun"); 478 errx(1,"corrupt patch (diff): overrun");
475 479
476 /* Read diff string */ 480 /* Read diff string */
477 cfread(&df, new + newpos, ctrl[0]); 481 cfread(&df, new + newpos, ctrl[0]);
478 482
479 /* Add old data to diff string */ 483 /* Add old data to diff string */
480 for(i=0;i<ctrl[0];i++) 484 for(i=0;i<ctrl[0];i++)
481 if((oldpos+i>=0) && (oldpos+i<oldsize)) 485 if((oldpos+i>=0) && (oldpos+i<oldsize))
482 new[newpos+i]+=old[oldpos+i]; 486 new[newpos+i]+=old[oldpos+i];
(...skipping 30 matching lines...) Expand all
513 /* Write the new file */ 517 /* Write the new file */
514 if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0644))<0) || 518 if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0644))<0) ||
515 (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) 519 (write(fd,new,newsize)!=newsize) || (close(fd)==-1))
516 err(1,"open/write/close(%s)",argv[2]); 520 err(1,"open/write/close(%s)",argv[2]);
517 521
518 free(new); 522 free(new);
519 free(old); 523 free(old);
520 524
521 return 0; 525 return 0;
522 } 526 }
OLDNEW
« no previous file with comments | « chrome/installer/mac/third_party/bsdiff/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698