[email protected], le dim. 28 sept. 2025 19:17:16 +0100, a ecrit:
> From: Diego Nieto Cid <[email protected]>
> 
>     ../../daemons/getty.c: In function 'main':
>     ../../daemons/getty.c:184:3: warning: ignoring return value of 'asprintf' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       184 |   asprintf (&ttyname, "%s/%s", _PATH_DEV, argv[2]);
>           |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     ../../daemons/getty.c:186:3: warning: ignoring return value of 'chown' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       186 |   chown (ttyname, 0, 0);
>           |   ^~~~~~~~~~~~~~~~~~~~~
>     ../../daemons/getty.c:188:3: warning: ignoring return value of 'revoke' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       188 |   revoke (ttyname);
>           |   ^~~~~~~~~~~~~~~~
>     ../../daemons/getty.c:210:3: warning: ignoring return value of 'asprintf' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       210 |   asprintf (&arg, "TERM=%s", tt ? tt->ty_type : "unknown");
>           |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     ../../daemons/getty.c: In function 'print_banner':
>     ../../daemons/getty.c:120:3: warning: ignoring return value of 'write' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       120 |   write (fd, "\r\n", 2);
>           |   ^~~~~~~~~~~~~~~~~~~~~
>     ../../daemons/getty.c:125:7: warning: ignoring return value of 'write' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       125 |       write (fd, s, t - s);
>           |       ^~~~~~~~~~~~~~~~~~~~
>     ../../daemons/getty.c:149:7: warning: ignoring return value of 'write' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       149 |       write (fd, expansion, strlen (expansion));
>           |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> =======================================================================
> 
>     ../../daemons/lmail.c: In function 'deliver':
>     ../../daemons/lmail.c:344:3: warning: ignoring return value of 'asprintf' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       344 |   asprintf (&mbox, "%s/%s", params->mail_dir, rcpt);
>           |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> =======================================================================
> 
>     ../../daemons/runttys.c: In function 'setup_terminal':
>     ../../daemons/runttys.c:105:7: warning: ignoring return value of 
> 'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result]
>       105 |       asprintf (&line, "%s %s", tt->ty_getty, tt->ty_name);
>           |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     ../../daemons/runttys.c: In function 'shutdown_terminal':
>     ../../daemons/runttys.c:323:3: warning: ignoring return value of 'revoke' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       323 |   revoke (t->name);
>           |   ^~~~~~~~~~~~~~~~
>     ../../daemons/runttys.c: In function 'main':
>     ../../daemons/runttys.c:474:7: warning: ignoring return value of 'write' 
> declared with attribute 'warn_unused_result' [-Wunused-result]
>       474 |       write (2, "", 0);
>           |       ^~~~~~~~~~~~~~~~
> ---
>  daemons/getty.c   | 52 +++++++++++++++++++++++++++++++++++++++--------
>  daemons/lmail.c   |  4 ++--
>  daemons/runttys.c | 11 ++++++----
>  3 files changed, 53 insertions(+), 14 deletions(-)
> 
> diff --git a/daemons/getty.c b/daemons/getty.c
> index b5b162d5..02ea414a 100644
> --- a/daemons/getty.c
> +++ b/daemons/getty.c
> @@ -35,6 +35,7 @@
>  #include <utmp.h>
>  #include <sys/ioctl.h>
>  #include <termios.h>
> +#include <assert-backtrace.h>
>  
>  /* XXX: should include directly from libshouldbeinlibc */
>  extern char *localhost (void);
> @@ -111,18 +112,21 @@ load_banner (void)
>  static void
>  print_banner (int fd, char *ttyname)
>  {
> +  ssize_t err;
>    char *s, *t, *expansion;
>    struct utsname u;
>  
>    if (uname (&u))
>      u.sysname[0] = u.release[0] = '\0';
>  
> -  write (fd, "\r\n", 2);
> +  err = write (fd, "\r\n", 2);
> +  assert_backtrace (err != -1);
>    for (s = load_banner (); *s; s++)
>      {
>        for (t = s; *t && *t != '\\'; t++) /* nomnomnom */;
>  
> -      write (fd, s, t - s);
> +      err = write (fd, s, t - s);
> +      assert_backtrace (err != -1);

You actually want to check that the return value is the number of bytes
that you have passed, otherwise we had a short-write. That'd be
surprising for a tty (normally it would just block), but better be safe
than risk losing characters.

>        if (! *t)
>          return;
>  
> @@ -146,7 +150,8 @@ print_banner (int fd, char *ttyname)
>          default:
>            expansion = "?";
>          }
> -      write (fd, expansion, strlen (expansion));
> +      err = write (fd, expansion, strlen (expansion));
> +      assert_backtrace (err != -1);
>  
>        s = t + 1;
>      }
> @@ -155,6 +160,7 @@ print_banner (int fd, char *ttyname)
>  int
>  main (int argc, char **argv)
>  {
> +  int err;
>    char *linespec, *ttyname;
>    int tty;
>    struct ttyent *tt;
> @@ -174,11 +180,35 @@ main (int argc, char **argv)
>    linespec = argv[1];
>  
>    tt = getttynam (argv[2]);
> -  asprintf (&ttyname, "%s/%s", _PATH_DEV, argv[2]);
> +  err = asprintf (&ttyname, "%s/%s", _PATH_DEV, argv[2]);
> +  if (err == -1)
> +    {
> +      syslog (LOG_ERR, "asprintf failed %s: %m", argv[2]);
> +      closelog ();
> +      exit (1);
> +    }
>  
> -  chown (ttyname, 0, 0);
> -  chmod (ttyname, 0600);
> -  revoke (ttyname);
> +  err = chown (ttyname, 0, 0);
> +  if (err == -1)
> +    {
> +      syslog (LOG_ERR, "chown failed %s: %m", ttyname);
> +      closelog ();
> +      exit (1);
> +    }
> +  err = chmod (ttyname, 0600);
> +  if (err == -1)
> +    {
> +      syslog (LOG_ERR, "chmod failed %s: %m", ttyname);
> +      closelog ();
> +      exit (1);
> +    }
> +  err = revoke (ttyname);
> +  if (err == -1)
> +    {
> +      syslog (LOG_ERR, "revoke failed %s; %m", ttyname);
> +      closelog ();
> +      exit (1);
> +    }
>    sleep (2);                 /* leave DTR down for a bit */
>  
>    do
> @@ -200,7 +230,13 @@ main (int argc, char **argv)
>    if (login_tty (tty) == -1)
>      syslog (LOG_ERR, "cannot set controlling terminal to %s: %m", ttyname);
>  
> -  asprintf (&arg, "TERM=%s", tt ? tt->ty_type : "unknown");
> +  err = asprintf (&arg, "TERM=%s", tt ? tt->ty_type : "unknown");
> +  if (err == -1)
> +    {
> +      syslog (LOG_ERR, "asprintf failed %s: %m", ttyname);
> +      closelog ();
> +      exit (1);
> +    }
>  
>    if (tt && strcmp (tt->ty_type, "dialup") == 0)
>      /* Dialup lines time out (which is login's default).  */
> diff --git a/daemons/lmail.c b/daemons/lmail.c
> index ee6b6fdc..513d33f8 100644
> --- a/daemons/lmail.c
> +++ b/daemons/lmail.c
> @@ -341,8 +341,8 @@ deliver (int msg, char *msg_name, char *rcpt, int flags, 
> struct params *params)
>    if (! pw)
>      return ERR ("%s: Unknown user", rcpt);
>  
> -  asprintf (&mbox, "%s/%s", params->mail_dir, rcpt);
> -  if (! mbox)
> +  int err = asprintf (&mbox, "%s/%s", params->mail_dir, rcpt);
> +  if (err == -1)
>      return SYSERRX (ENOMEM, "%s", rcpt);
>  
>    do
> diff --git a/daemons/runttys.c b/daemons/runttys.c
> index 1b4b3601..2eff7e7b 100644
> --- a/daemons/runttys.c
> +++ b/daemons/runttys.c
> @@ -102,8 +102,8 @@ setup_terminal (struct terminal *t, struct ttyent *tt)
>       }
>  
>        char *line;
> -      asprintf (&line, "%s %s", tt->ty_getty, tt->ty_name);
> -      if (line == 0)
> +      int err = asprintf (&line, "%s %s", tt->ty_getty, tt->ty_name);
> +      if (err == -1)
>       {
>         error (0, ENOMEM,
>                "cannot allocate arguments for %s", t->name);
> @@ -319,8 +319,10 @@ restart_terminal (pid_t pid)
>  static void
>  shutdown_terminal (struct terminal *t)
>  {
> +  int err;
>    kill (t->pid, SIGHUP);
> -  revoke (t->name);
> +  err = revoke (t->name);
> +  assert_backtrace (err != -1);
>  }
>  
>  /* Re-read /etc/ttys.  If a line has turned off, kill what's there.
> @@ -471,7 +473,8 @@ main (void)
>        /* Elicit a SIGLOST now if the console (on our stderr, i.e. fd 2) has
>        died.  That way, the next error message emitted will actually make
>        it out to the console if it can be made it work at all.  */
> -      write (2, "", 0);
> +      int err = write (2, "", 0);
> +      assert_backtrace (err != -1);
>  
>        /* If a SIGTERM or SIGHUP arrived recently, it set a flag
>        and broke us out of being blocked in waitpid.  */
> -- 
> 2.51.0
> 
> 

-- 
Samuel
       La  fonction  memfrob() crypte les n premiers octets de la
       zone de mémoire  s  en  effectuant  un  OU-exclusif  entre
       chaque  octet  et le nombre 42.
(extrait de la page de man de memfrob -- Manuel du programmeur Linux)

Reply via email to