patch-main_c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. $OpenBSD: patch-main_c,v 1.2 2007/01/04 23:38:23 kili Exp $
  2. --- main.c.orig Mon Feb 13 19:38:23 2006
  3. +++ main.c Mon Jan 1 18:26:21 2007
  4. @@ -51,7 +51,7 @@ static void write_magic(int fd_in, int f
  5. uint32_t v;
  6. memset(magic, 0, sizeof(magic));
  7. - strcpy(magic, "RZIP");
  8. + strncpy(magic, "RZIP", 4);
  9. magic[4] = RZIP_MAJOR_VERSION;
  10. magic[5] = RZIP_MINOR_VERSION;
  11. @@ -131,6 +131,9 @@ static void decompress_file(struct rzip_
  12. if (control->outname) {
  13. control->outfile = strdup(control->outname);
  14. + if (control->outfile == NULL) {
  15. + fatal("Failed to allocate memory for output filename");
  16. + }
  17. } else {
  18. if (strlen(control->suffix) >= strlen(control->infile) ||
  19. strcmp(control->suffix,
  20. @@ -140,6 +143,9 @@ static void decompress_file(struct rzip_
  21. }
  22. control->outfile = strdup(control->infile);
  23. + if (control->outfile == NULL) {
  24. + fatal("Failed to allocate memory for output filename");
  25. + }
  26. control->outfile[strlen(control->infile) - strlen(control->suffix)] = 0;
  27. }
  28. @@ -208,14 +214,19 @@ static void compress_file(struct rzip_co
  29. if (control->outname) {
  30. control->outfile = strdup(control->outname);
  31. + if (control->outfile == NULL) {
  32. + fatal("Failed to allocate memory for output filename");
  33. + }
  34. } else {
  35. - control->outfile = malloc(strlen(control->infile) +
  36. - strlen(control->suffix) + 1);
  37. + size_t len;
  38. +
  39. + len = strlen(control->infile) + strlen(control->suffix) + 1;
  40. + control->outfile = malloc(len);
  41. if (!control->outfile) {
  42. fatal("Failed to allocate outfile name\n");
  43. }
  44. - strcpy(control->outfile, control->infile);
  45. - strcat(control->outfile, control->suffix);
  46. + strlcpy(control->outfile, control->infile, len);
  47. + strlcat(control->outfile, control->suffix, len);
  48. }
  49. fd_in = open(control->infile,O_RDONLY);