logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0002-Avoid-pointer-arithmetic-on-void.patch (9982B)


  1. From 2bb631b109219f0e9bea49294b9408269ce9b5ee Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Sat, 1 May 2021 01:37:10 -0700
  4. Subject: [PATCH] Avoid pointer arithmetic on `void *`
  5. void is an incomplete type, so cannot be used in pointer arithmetic.
  6. ---
  7. tools/aisimage.c | 2 +-
  8. tools/default_image.c | 4 ++--
  9. tools/mtk_image.c | 6 +++---
  10. tools/omapimage.c | 10 +++++-----
  11. tools/rkcommon.c | 10 +++++-----
  12. tools/rkspi.c | 6 +++---
  13. tools/socfpgaimage.c | 2 +-
  14. tools/stm32image.c | 2 +-
  15. tools/zynqmpbif.c | 8 ++++----
  16. tools/zynqmpimage.c | 8 ++++----
  17. 10 files changed, 29 insertions(+), 29 deletions(-)
  18. diff --git a/tools/aisimage.c b/tools/aisimage.c
  19. index b8b3ee3207..58eb596844 100644
  20. --- a/tools/aisimage.c
  21. +++ b/tools/aisimage.c
  22. @@ -148,7 +148,7 @@ static void aisimage_print_header(const void *hdr)
  23. fprintf(stdout, "AIS cmd : %s\n",
  24. get_table_entry_name(aisimage_cmds, NULL, id));
  25. ptr += cmd_table[id].nargs + IS_FNC_EXEC(id) + 1;
  26. - if (((void *)ptr - hdr) > ais_img_size) {
  27. + if ((char *)ptr - (char *)hdr > ais_img_size) {
  28. fprintf(stderr,
  29. "AIS Image not terminated by JMPCLOSE\n");
  30. return;
  31. diff --git a/tools/default_image.c b/tools/default_image.c
  32. index e164c0c27d..d2e3688908 100644
  33. --- a/tools/default_image.c
  34. +++ b/tools/default_image.c
  35. @@ -98,8 +98,8 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd,
  36. image_header_t * hdr = (image_header_t *)ptr;
  37. checksum = crc32(0,
  38. - (const unsigned char *)(ptr +
  39. - sizeof(image_header_t)),
  40. + (const unsigned char *)ptr +
  41. + sizeof(image_header_t),
  42. sbuf->st_size - sizeof(image_header_t));
  43. time = imagetool_get_source_date(params->cmdname, sbuf->st_mtime);
  44. diff --git a/tools/mtk_image.c b/tools/mtk_image.c
  45. index bde1e5da4b..3038402413 100644
  46. --- a/tools/mtk_image.c
  47. +++ b/tools/mtk_image.c
  48. @@ -688,7 +688,7 @@ static void mtk_image_set_gen_header(void *ptr, off_t filesize,
  49. hdr->brlyt.total_size_2 = hdr->brlyt.total_size;
  50. /* GFH header */
  51. - gfh = (struct gfh_header *)(ptr + sizeof(struct gen_device_header));
  52. + gfh = (struct gfh_header *)((char *)ptr + sizeof(struct gen_device_header));
  53. put_ghf_header(gfh, filesize, sizeof(struct gen_device_header),
  54. loadaddr, GFH_FLASH_TYPE_GEN);
  55. @@ -714,7 +714,7 @@ static void mtk_image_set_nand_header(void *ptr, off_t filesize,
  56. payload_pages = (filesize + le16_to_cpu(hdr_nand->pagesize) - 1) /
  57. le16_to_cpu(hdr_nand->pagesize);
  58. brlyt = (struct brom_layout_header *)
  59. - (ptr + le16_to_cpu(hdr_nand->pagesize));
  60. + ((char *)ptr + le16_to_cpu(hdr_nand->pagesize));
  61. put_brom_layout_header(brlyt, hdr_media);
  62. brlyt->header_size = cpu_to_le32(2);
  63. brlyt->total_size = cpu_to_le32(payload_pages);
  64. @@ -723,7 +723,7 @@ static void mtk_image_set_nand_header(void *ptr, off_t filesize,
  65. brlyt->unused = cpu_to_le32(1);
  66. /* GFH header */
  67. - gfh = (struct gfh_header *)(ptr + 2 * le16_to_cpu(hdr_nand->pagesize));
  68. + gfh = (struct gfh_header *)((char *)ptr + 2 * le16_to_cpu(hdr_nand->pagesize));
  69. put_ghf_header(gfh, filesize, 2 * le16_to_cpu(hdr_nand->pagesize),
  70. loadaddr, GFH_FLASH_TYPE_NAND);
  71. diff --git a/tools/omapimage.c b/tools/omapimage.c
  72. index c59cdcc79b..90c279fb05 100644
  73. --- a/tools/omapimage.c
  74. +++ b/tools/omapimage.c
  75. @@ -89,7 +89,7 @@ static void omapimage_print_header(const void *ptr)
  76. {
  77. const struct ch_toc *toc = (struct ch_toc *)ptr;
  78. const struct gp_header *gph =
  79. - (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
  80. + (struct gp_header *)((char *)ptr+OMAP_CH_HDR_SIZE);
  81. uint32_t offset, size;
  82. while (toc->section_offset != 0xffffffff
  83. @@ -111,7 +111,7 @@ static void omapimage_print_header(const void *ptr)
  84. toc->section_offset,
  85. toc->section_size);
  86. - omapimage_print_section((struct ch_settings *)(ptr+offset));
  87. + omapimage_print_section((struct ch_settings *)((char *)ptr+offset));
  88. toc++;
  89. }
  90. @@ -120,7 +120,7 @@ static void omapimage_print_header(const void *ptr)
  91. static int toc_offset(void *hdr, void *member)
  92. {
  93. - return member - hdr;
  94. + return (char *)member - (char *)hdr;
  95. }
  96. static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd,
  97. @@ -128,8 +128,8 @@ static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd,
  98. {
  99. struct ch_toc *toc = (struct ch_toc *)ptr;
  100. struct ch_settings *chs = (struct ch_settings *)
  101. - (ptr + 2 * sizeof(*toc));
  102. - struct gp_header *gph = (struct gp_header *)(ptr + OMAP_CH_HDR_SIZE);
  103. + ((char *)ptr + 2 * sizeof(*toc));
  104. + struct gp_header *gph = (struct gp_header *)((char *)ptr + OMAP_CH_HDR_SIZE);
  105. toc->section_offset = toc_offset(ptr, chs);
  106. toc->section_size = sizeof(struct ch_settings);
  107. diff --git a/tools/rkcommon.c b/tools/rkcommon.c
  108. index d55cd2c2d5..8853b2560c 100644
  109. --- a/tools/rkcommon.c
  110. +++ b/tools/rkcommon.c
  111. @@ -249,7 +249,7 @@ static void rkcommon_set_header0(void *buf, struct image_tool_params *params)
  112. void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd,
  113. struct image_tool_params *params)
  114. {
  115. - struct header1_info *hdr = buf + RK_SPL_HDR_START;
  116. + struct header1_info *hdr = (void *)((char *)buf + RK_SPL_HDR_START);
  117. rkcommon_set_header0(buf, params);
  118. @@ -262,7 +262,7 @@ void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd,
  119. if (spl_params.boot_file) {
  120. if (rkcommon_need_rc4_spl(params))
  121. - rkcommon_rc4_encode_spl(buf + RK_SPL_HDR_START,
  122. + rkcommon_rc4_encode_spl((char *)buf + RK_SPL_HDR_START,
  123. spl_params.init_size,
  124. spl_params.boot_size);
  125. }
  126. @@ -302,8 +302,8 @@ static int rkcommon_parse_header(const void *buf, struct header0_info *header0,
  127. return -ENOSYS;
  128. hdr1_offset = le16_to_cpu(header0->init_offset) * RK_BLK_SIZE;
  129. - hdr1_sdmmc = (struct header1_info *)(buf + hdr1_offset);
  130. - hdr1_spi = (struct header1_info *)(buf +
  131. + hdr1_sdmmc = (struct header1_info *)((char *)buf + hdr1_offset);
  132. + hdr1_spi = (struct header1_info *)((char *)buf +
  133. rkcommon_offset_to_spi(hdr1_offset));
  134. for (i = 0; i < ARRAY_SIZE(spl_infos); i++) {
  135. @@ -392,7 +392,7 @@ void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size)
  136. while (remaining > 0) {
  137. int step = (remaining > RK_BLK_SIZE) ? RK_BLK_SIZE : remaining;
  138. - rc4_encode(buf + offset, step, rc4_key);
  139. + rc4_encode((char *)buf + offset, step, rc4_key);
  140. offset += RK_BLK_SIZE;
  141. remaining -= step;
  142. }
  143. diff --git a/tools/rkspi.c b/tools/rkspi.c
  144. index f2530f7bde..7bd13f3749 100644
  145. --- a/tools/rkspi.c
  146. +++ b/tools/rkspi.c
  147. @@ -37,10 +37,10 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd,
  148. for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) {
  149. debug("sector %u\n", sector);
  150. - memmove(buf + sector * RKSPI_SECT_LEN * 2,
  151. - buf + sector * RKSPI_SECT_LEN,
  152. + memmove((char *)buf + sector * RKSPI_SECT_LEN * 2,
  153. + (char *)buf + sector * RKSPI_SECT_LEN,
  154. RKSPI_SECT_LEN);
  155. - memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
  156. + memset((char *)buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
  157. '\0', RKSPI_SECT_LEN);
  158. }
  159. }
  160. diff --git a/tools/socfpgaimage.c b/tools/socfpgaimage.c
  161. index eba812fec9..a206323d6c 100644
  162. --- a/tools/socfpgaimage.c
  163. +++ b/tools/socfpgaimage.c
  164. @@ -315,7 +315,7 @@ static void socfpgaimage_print_header_v1(struct socfpga_header_v1 *header)
  165. static void socfpgaimage_print_header(const void *ptr)
  166. {
  167. - const void *header = ptr + HEADER_OFFSET;
  168. + const void *header = (char *)ptr + HEADER_OFFSET;
  169. struct socfpga_header_v0 *header_v0;
  170. if (sfp_verify_buffer(ptr) == 0) {
  171. diff --git a/tools/stm32image.c b/tools/stm32image.c
  172. index 18357c0518..9252362654 100644
  173. --- a/tools/stm32image.c
  174. +++ b/tools/stm32image.c
  175. @@ -58,7 +58,7 @@ static uint32_t stm32image_checksum(void *start, uint32_t len)
  176. if (len < hdr_len)
  177. return 0;
  178. - p = start + hdr_len;
  179. + p = (uint8_t *)((char *)start + hdr_len);
  180. len -= hdr_len;
  181. while (len > 0) {
  182. diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c
  183. index 82ce0ac1a5..04325afa20 100644
  184. --- a/tools/zynqmpbif.c
  185. +++ b/tools/zynqmpbif.c
  186. @@ -262,7 +262,7 @@ static int bif_add_blob(const void *data, size_t len, size_t *offset)
  187. new_size = ROUND(bif_output.data_len + len, 64);
  188. new_data = realloc(bif_output.data, new_size);
  189. - memcpy(new_data + bif_output.data_len, data, len);
  190. + memcpy((char *)new_data + bif_output.data_len, data, len);
  191. if (offset)
  192. *offset = bif_output.data_len;
  193. bif_output.data = new_data;
  194. @@ -270,11 +270,11 @@ static int bif_add_blob(const void *data, size_t len, size_t *offset)
  195. /* Readjust internal pointers */
  196. if (bif_output.header)
  197. - bif_output.header = new_data + header_off;
  198. + bif_output.header = (void *)((char *)new_data + header_off);
  199. if (bif_output.last_part)
  200. - bif_output.last_part = new_data + last_part_off;
  201. + bif_output.last_part = (void *)((char *)new_data + last_part_off);
  202. if (bif_output.imgheader)
  203. - bif_output.imgheader = new_data + imgheader_off;
  204. + bif_output.imgheader = (void *)((char *)new_data + imgheader_off);
  205. return 0;
  206. }
  207. diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c
  208. index 19b2f02ff1..20122d1320 100644
  209. --- a/tools/zynqmpimage.c
  210. +++ b/tools/zynqmpimage.c
  211. @@ -250,15 +250,15 @@ void zynqmpimage_print_header(const void *ptr)
  212. }
  213. if (zynqhdr->image_header_table_offset) {
  214. - struct image_header_table *iht = (void *)ptr +
  215. - zynqhdr->image_header_table_offset;
  216. + struct image_header_table *iht = (void *)((char *)ptr +
  217. + zynqhdr->image_header_table_offset);
  218. struct partition_header *ph;
  219. uint32_t ph_offset;
  220. uint32_t next;
  221. int i;
  222. ph_offset = le32_to_cpu(iht->partition_header_offset) * 4;
  223. - ph = (void *)ptr + ph_offset;
  224. + ph = (void *)((char *)ptr + ph_offset);
  225. for (i = 0; i < le32_to_cpu(iht->nr_parts); i++) {
  226. next = le32_to_cpu(ph->next_partition_offset) * 4;
  227. @@ -266,7 +266,7 @@ void zynqmpimage_print_header(const void *ptr)
  228. if (i)
  229. print_partition(ptr, ph);
  230. - ph = (void *)ptr + next;
  231. + ph = (void *)((char *)ptr + next);
  232. }
  233. }
  234. --
  235. 2.31.1