write: fix potential string overflow

Noticed when compiled with gcc verion 9.2.1 20200130.

term-utils/write.c:182:7: warning: ‘strcmp’ argument 1 declared attribute
			  ‘nonstring’ [-Wstringop-overflow=]
  182 |   if (strcmp(u->ut_line, ctl->src_tty_name) == 0) {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/utmpx.h:31,
                 from term-utils/write.c:60:
/usr/include/bits/utmpx.h:59:8: note: argument ‘ut_line’ declared here
   59 |   char ut_line[__UT_LINESIZE]
      |        ^~~~~~~

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
pull/954/head
Sami Kerola 3 years ago
parent 3239663361
commit cdf84bf658
No known key found for this signature in database
GPG Key ID: 0D46FEF7E61DBB46
  1. 2
      term-utils/write.c

@ -179,7 +179,7 @@ static void search_utmp(struct write_control *ctl)
if (ctl->src_uid && !tty_writeable)
/* skip ttys with msgs off */
continue;
if (strcmp(u->ut_line, ctl->src_tty_name) == 0) {
if (memcmp(u->ut_line, ctl->src_tty_name, strlen(ctl->src_tty_name) + 1) == 0) {
user_is_me = 1;
/* don't write to yourself */
continue;

Loading…
Cancel
Save