bash-4.2-coverity.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. diff --git a/execute_cmd.c b/execute_cmd.c
  2. index a988400..412128c 100644
  3. --- a/execute_cmd.c
  4. +++ b/execute_cmd.c
  5. @@ -5760,7 +5760,7 @@ shell_execve (command, args, env)
  6. Elf32_Ehdr ehdr;
  7. Elf32_Phdr *phdr;
  8. Elf32_Shdr *shdr;
  9. - int nphdr, nshdr;
  10. + Elf32_Half nphdr, nshdr;
  11. /* We have to copy the data since the sample buffer
  12. might not be aligned correctly to be accessed as
  13. @@ -5768,12 +5768,12 @@ shell_execve (command, args, env)
  14. memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
  15. nshdr = ehdr.e_shnum;
  16. - shdr = (Elf32_Shdr *) malloc (nshdr * ehdr.e_shentsize);
  17. + shdr = (Elf32_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize);
  18. if (shdr != NULL)
  19. {
  20. #ifdef HAVE_PREAD
  21. - sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
  22. + sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize,
  23. ehdr.e_shoff);
  24. #else
  25. if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
  26. @@ -5815,11 +5815,11 @@ shell_execve (command, args, env)
  27. }
  28. nphdr = ehdr.e_phnum;
  29. - phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
  30. + phdr = (Elf32_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize);
  31. if (phdr != NULL)
  32. {
  33. #ifdef HAVE_PREAD
  34. - sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
  35. + sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize,
  36. ehdr.e_phoff);
  37. #else
  38. if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
  39. @@ -5844,7 +5844,7 @@ shell_execve (command, args, env)
  40. Elf64_Ehdr ehdr;
  41. Elf64_Phdr *phdr;
  42. Elf64_Shdr *shdr;
  43. - int nphdr, nshdr;
  44. + Elf32_Half nphdr, nshdr;
  45. /* We have to copy the data since the sample buffer
  46. might not be aligned correctly to be accessed as
  47. @@ -5852,11 +5852,11 @@ shell_execve (command, args, env)
  48. memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
  49. nshdr = ehdr.e_shnum;
  50. - shdr = (Elf64_Shdr *) malloc (nshdr * ehdr.e_shentsize);
  51. + shdr = (Elf64_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize);
  52. if (shdr != NULL)
  53. {
  54. #ifdef HAVE_PREAD
  55. - sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
  56. + sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize,
  57. ehdr.e_shoff);
  58. #else
  59. if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
  60. @@ -5898,11 +5898,11 @@ shell_execve (command, args, env)
  61. }
  62. nphdr = ehdr.e_phnum;
  63. - phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
  64. + phdr = (Elf64_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize);
  65. if (phdr != NULL)
  66. {
  67. #ifdef HAVE_PREAD
  68. - sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
  69. + sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize,
  70. ehdr.e_phoff);
  71. #else
  72. if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
  73. @@ -5924,8 +5924,8 @@ shell_execve (command, args, env)
  74. if (offset != -1)
  75. {
  76. - size_t maxlen = 0;
  77. - size_t actlen = 0;
  78. + ssize_t maxlen = 0;
  79. + ssize_t actlen = 0;
  80. char *interp = NULL;
  81. do
  82. @@ -5974,7 +5974,8 @@ shell_execve (command, args, env)
  83. }
  84. #endif
  85. #if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
  86. - close (fd);
  87. + if (fd >= 0)
  88. + close (fd);
  89. #endif
  90. errno = i;
  91. --
  92. 2.17.2