mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Waldek Kozaczuk <jwkozaczuk@gmail.com>
To: musl@lists.openwall.com
Subject: [musl] Both network/if_nametoindex.c and network/if_indextoname.c should use strlcpy instead of strncpy
Date: Mon, 17 Aug 2020 00:12:30 -0400	[thread overview]
Message-ID: <CAL9cFfM+kiH+jrpADhvxnZa3-4wM64BKye8=MBz9OVtJyctQpQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 980 bytes --]

Hi,

As I have been working on upgrading OSv (
https://github.com/cloudius-systems/osv) to latest version of musl, I have
noticed that both network/if_nametoindex.c and network/if_indextoname.c use
strncpy() to copy interface name to/from buffer. In both cases per
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/net_if.h.html and
https://linux.die.net/man/3/if_indextoname, it seems that  ifname should be
big enough to hold IF_NAMESIZE bytes which SHOULD include null terminating
one. If that is the case both functions should use strlcpy instead of
strncpy.

Am I wrong?

My regards,
Waldemar Kozaczuk

PS. Trying to compile if_nameindex() yields warning:

  CC musl/src/network/if_nameindex.c
include/api/net/if.h: In function ‘if_nametoindex’:
musl/src/network/if_nametoindex.c:14:2: error: ‘strncpy’ specified bound 16
equals destination size [-Werror=stringop-truncation]
   14 |  strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);

[-- Attachment #2: Type: text/html, Size: 1327 bytes --]

             reply	other threads:[~2020-08-17  7:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17  4:12 Waldek Kozaczuk [this message]
2020-08-17 23:54 ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAL9cFfM+kiH+jrpADhvxnZa3-4wM64BKye8=MBz9OVtJyctQpQ@mail.gmail.com' \
    --to=jwkozaczuk@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).