Page MenuHomeFreeBSD

Replace strlen with strnlen.
AbandonedPublic

Authored by araujo on Jan 29 2019, 12:15 PM.
Tags
None
Referenced Files
F111977451: D19016.id53370.diff
Tue, Mar 11, 2:29 AM
Unknown Object (File)
Sat, Mar 8, 1:50 PM
Unknown Object (File)
Sat, Feb 22, 12:25 AM
Unknown Object (File)
Jan 25 2025, 6:02 AM
Unknown Object (File)
Jan 23 2025, 1:25 PM
Unknown Object (File)
Jan 17 2025, 3:41 PM
Unknown Object (File)
Nov 24 2024, 6:48 AM
Unknown Object (File)
Nov 6 2024, 11:41 PM

Details

Reviewers
rgrimes
Group Reviewers
bhyve
Summary

These are most cosmetic changes.

Obtained from: Intel.

Test Plan

With guests:

  • Windows Server.
  • Linux Fedora.
  • FreeBSD HEAD.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 22265
Build 21466: arc lint + arc unit

Event Timeline

usr.sbin/bhyve/bhyverun.c
236–237

While using strlnlen() here will guard against the insane notion that progname could be longer than PATH_MAX, it won't prevent fprintf from outputting an insane number of characters for progname should it be an unbounded string.

usr.sbin/bhyve/pci_virtio_net.c
891 ↗(On Diff #53370)

there's no way that nstr won't be terminated in the first 80 characters because the snprintf 3 lines above guarantees it. so strnlen() is kinda useless here.

Revert strnlen to strlen on pci_virtio_net as snprintf does the job already.

usr.sbin/bhyve/bhyverun.c
236–237

@imp do you have any suggestion for the fprintf case?

It is basically a cosmetic change, so I have committed it already: r343634.

cem added inline comments.
usr.sbin/bhyve/bhyverun.c
236–237

@araujo the format string "%.*s" can be used to bound the length of string printed. Similar to the "%*s" padding entries that follow, two arguments are passed to printf for this format: int length, and (const) char * string. Only the first length bytes are formatted.

That said, I don't think strnlen() is useful here, so the simpler thing to do is just leave it alone.