bash-4.2-coverity.patch 3.4 KB

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