fastjar-jartool.c_rev1.62.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. http://cvs.savannah.gnu.org/viewvc/fastjar/jartool.c?root=fastjar&r1=1.59&r2=1.62&view=patch
  2. Revision 1.62 - Thu Jun 10 11:32:48 2010 UTC (5 years, 6 months ago) by richi
  3. 2010-06-10 Jakub Jelinek <jakub@redhat.com>
  4. Dan Rosenberg <dan.j.rosenberg@gmail.com>
  5. * jartool.c (extract_jar): Fix up checks for traversal to parent
  6. directories, disallow absolute paths, make the code slightly more
  7. efficient.
  8. Revision 1.61 - Thu Jun 10 08:46:10 2010 UTC (5 years, 6 months ago) by richi
  9. 2010-06-10 Chris Ball <cjb@laptop.org>
  10. * jartool.c (add_file_to_jar): Fix write return value check.
  11. Revision 1.60 - Mon Mar 1 15:38:43 2010 UTC (5 years, 9 months ago) by richi
  12. 2010-03-01 Richard Guenther <rguenther@suse.de>
  13. * jartool.c (read_entries): Properly zero-terminate filename.
  14. --- jartool.c 2009/09/06 22:16:00 1.59
  15. +++ jartool.c 2010/06/10 11:32:48 1.62
  16. @@ -790,6 +790,7 @@
  17. progname, jarfile);
  18. return 1;
  19. }
  20. + ze->filename[len] = '\0';
  21. len = UNPACK_UB4(header, CEN_EFLEN);
  22. len += UNPACK_UB4(header, CEN_COMLEN);
  23. if (lseek (fd, len, SEEK_CUR) == -1)
  24. @@ -1257,7 +1258,7 @@
  25. exit_on_error("write");
  26. /* write the file name to the zip file */
  27. - if (1 == write(jfd, fname, file_name_length))
  28. + if (-1 == write(jfd, fname, file_name_length))
  29. exit_on_error("write");
  30. if(verbose){
  31. @@ -1730,7 +1731,17 @@
  32. struct stat sbuf;
  33. int depth = 0;
  34. - tmp_buff = malloc(sizeof(char) * strlen((const char *)filename));
  35. + if(*filename == '/'){
  36. + fprintf(stderr, "Absolute path names are not allowed.\n");
  37. + exit(EXIT_FAILURE);
  38. + }
  39. +
  40. + tmp_buff = malloc(strlen((const char *)filename));
  41. +
  42. + if(tmp_buff == NULL) {
  43. + fprintf(stderr, "Out of memory.\n");
  44. + exit(EXIT_FAILURE);
  45. + }
  46. for(;;){
  47. const ub1 *idx = (const unsigned char *)strchr((const char *)start, '/');
  48. @@ -1738,25 +1749,28 @@
  49. if(idx == NULL)
  50. break;
  51. else if(idx == start){
  52. + tmp_buff[idx - filename] = '/';
  53. start++;
  54. continue;
  55. }
  56. - start = idx + 1;
  57. - strncpy(tmp_buff, (const char *)filename, (idx - filename));
  58. - tmp_buff[(idx - filename)] = '\0';
  59. + memcpy(tmp_buff + (start - filename), (const char *)start, (idx - start));
  60. + tmp_buff[idx - filename] = '\0';
  61. #ifdef DEBUG
  62. printf("checking the existance of %s\n", tmp_buff);
  63. #endif
  64. - if(strcmp(tmp_buff, "..") == 0){
  65. + if(idx - start == 2 && memcmp(start, "..", 2) == 0){
  66. --depth;
  67. if (depth < 0){
  68. fprintf(stderr, "Traversal to parent directories during unpacking!\n");
  69. exit(EXIT_FAILURE);
  70. }
  71. - } else if (strcmp(tmp_buff, ".") != 0)
  72. + } else if (idx - start != 1 || *start != '.')
  73. ++depth;
  74. +
  75. + start = idx + 1;
  76. +
  77. if(stat(tmp_buff, &sbuf) < 0){
  78. if(errno != ENOENT)
  79. exit_on_error("stat");
  80. @@ -1765,6 +1779,7 @@
  81. #ifdef DEBUG
  82. printf("Directory exists\n");
  83. #endif
  84. + tmp_buff[idx - filename] = '/';
  85. continue;
  86. }else {
  87. fprintf(stderr, "Hmmm.. %s exists but isn't a directory!\n",
  88. @@ -1781,10 +1796,11 @@
  89. if(verbose && handle)
  90. printf("%10s: %s/\n", "created", tmp_buff);
  91. + tmp_buff[idx - filename] = '/';
  92. }
  93. /* only a directory */
  94. - if(strlen((const char *)start) == 0)
  95. + if(*start == '\0')
  96. dir = TRUE;
  97. #ifdef DEBUG
  98. @@ -1792,7 +1808,7 @@
  99. #endif
  100. /* If the entry was just a directory, don't write to file, etc */
  101. - if(strlen((const char *)start) == 0)
  102. + if(*start == '\0')
  103. f_fd = -1;
  104. free(tmp_buff);
  105. @@ -1876,7 +1892,8 @@
  106. exit(EXIT_FAILURE);
  107. }
  108. - close(f_fd);
  109. + if (f_fd != -1)
  110. + close(f_fd);
  111. if(verbose && dir == FALSE && handle)
  112. printf("%10s: %s\n",