[email protected], le dim. 28 sept. 2025 19:17:19 +0100, a ecrit:
> From: Diego Nieto Cid <[email protected]>
>
> ../../boot/userland-boot.c: In function 'boot_script_prompt_task_resume':
> ../../boot/userland-boot.c:96:3: warning: ignoring return value of
> 'fgets' declared with attribute 'warn_unused_result' [-Wunused-result]
>
> ../../boot/userland-boot.c: In function 'boot_script_exec_cmd':
> ../../boot/userland-boot.c:267:3: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:271:7: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:273:9: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:274:7: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:276:9: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:278:3: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
>
> ../../boot/userland-boot.c: In function 'load_image':
> ../../boot/userland-boot.c:179:7: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:180:7: warning: ignoring return value of
> 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:185:3: warning: ignoring return value of
> 'read' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:192:7: warning: ignoring return value of
> 'read' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:204:13: warning: ignoring return value of
> 'read' declared with attribute 'warn_unused_result' [-Wunused-result]
> ../../boot/userland-boot.c:237:7: warning: ignoring return value of
> 'read' declared with attribute 'warn_unused_result' [-Wunused-result]
> ---
> boot/userland-boot.c | 49 +++++++++++++++++++++++++++++++-------------
> 1 file changed, 35 insertions(+), 14 deletions(-)
>
> diff --git a/boot/userland-boot.c b/boot/userland-boot.c
> index 09a9dc26..65a5d9a7 100644
> --- a/boot/userland-boot.c
> +++ b/boot/userland-boot.c
> @@ -31,6 +31,7 @@
> #include <errno.h>
> #include <error.h>
> #include <link.h>
> +#include <assert-backtrace.h>
>
> #include "boot_script.h"
> #include "private.h"
> @@ -94,10 +95,12 @@ boot_script_task_resume (struct cmd *cmd)
> int
> boot_script_prompt_task_resume (struct cmd *cmd)
> {
> - char xx[5];
> + int c;
>
> printf ("Hit return to resume %s...", cmd->path);
> - fgets (xx, sizeof xx, stdin);
> + do {
> + c = fgetc (stdin);
> + } while (c != EOF && c != '\n');
>
> return boot_script_task_resume (cmd);
> }
> @@ -168,6 +171,7 @@ static vm_address_t
> load_image (task_t t,
> char *file)
> {
> + ssize_t err;
> int fd;
> union
> {
> @@ -180,20 +184,24 @@ load_image (task_t t,
>
> if (fd == -1)
> {
> - write (2, file, strlen (file));
> - write (2, msg, sizeof msg - 1);
> + err = write (2, file, strlen (file));
> + assert_backtrace (err != -1);
> + err = write (2, msg, sizeof msg - 1);
> + assert_backtrace (err != -1);
> task_terminate (t);
> exit (1);
> }
>
> - read (fd, &hdr, sizeof hdr);
> + err = read (fd, &hdr, sizeof hdr);
> + assert_backtrace (err != -1);
Here also, we want to check for the size being read, as well as below.
> /* File must have magic ELF number. */
> if (hdr.e.e_ident[0] == 0177 && hdr.e.e_ident[1] == 'E' &&
> hdr.e.e_ident[2] == 'L' && hdr.e.e_ident[3] == 'F')
> {
> ElfW(Phdr) phdrs[hdr.e.e_phnum], *ph;
> lseek (fd, hdr.e.e_phoff, SEEK_SET);
> - read (fd, phdrs, sizeof phdrs);
> + err = read (fd, phdrs, sizeof phdrs);
> + assert_backtrace (err != -1);
> for (ph = phdrs; ph < &phdrs[sizeof phdrs/sizeof phdrs[0]]; ++ph)
> if (ph->p_type == PT_LOAD)
> {
> @@ -205,7 +213,8 @@ load_image (task_t t,
> PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
>
> lseek (fd, ph->p_offset, SEEK_SET);
> - read (fd, (void *)(buf + offs), ph->p_filesz);
> + err = read (fd, (void *)(buf + offs), ph->p_filesz);
> + assert_backtrace (err != -1);
>
> ph->p_memsz = ((ph->p_vaddr + ph->p_memsz + ph->p_align - 1)
> & ~(ph->p_align - 1));
> @@ -238,7 +247,8 @@ load_image (task_t t,
> rndamount = round_page (amount);
> buf = mmap (0, rndamount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
> lseek (fd, sizeof hdr.a - headercruft, SEEK_SET);
> - read (fd, buf, amount);
> + err = read (fd, buf, amount);
> + assert_backtrace (err != -1);
> vm_allocate (t, &base, rndamount, 0);
> vm_write (t, base, (vm_address_t) buf, rndamount);
> if (magic != OMAGIC)
> @@ -267,19 +277,30 @@ boot_script_exec_cmd (void *hook,
> vm_offset_t stack_start, stack_end;
> vm_address_t startpc, str_start;
> thread_t thread;
> + ssize_t err;
>
> - write (2, path, strlen (path));
> + err = write (2, path, strlen (path));
> + assert_backtrace (err != -1);
> for (i = 1; i < argc; ++i)
> {
> int quote = !! index (argv[i], ' ') || !! index (argv[i], '\t');
> - write (2, " ", 1);
> + err = write (2, " ", 1);
> + assert_backtrace (err != -1);
> if (quote)
> - write (2, "\"", 1);
> - write (2, argv[i], strlen (argv[i]));
> + {
> + err = write (2, "\"", 1);
> + assert_backtrace (err != -1);
> + }
> + err = write (2, argv[i], strlen (argv[i]));
> + assert_backtrace (err != -1);
> if (quote)
> - write (2, "\"", 1);
> + {
> + err = write (2, "\"", 1);
> + assert_backtrace (err != -1);
> + }
> }
> - write (2, "\r\n", 2);
> + err = write (2, "\r\n", 2);
> + assert_backtrace (err != -1);
>
> startpc = load_image (task, path);
> arg_len = stringlen + (argc + 2) * sizeof (char *) + sizeof (intptr_t);
> --
> 2.51.0
>
>
--
Samuel
"...Deep Hack Mode--that mysterious and frightening state of
consciousness where Mortal Users fear to tread."
(By Matt Welsh)