Page MenuHomeFreeBSD

Replace strlen with strnlen.
AbandonedPublic

Authored by araujo on Jan 29 2019, 12:15 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
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 22245
Build 21448: arc lint + arc unit

Event Timeline

araujo created this revision.Jan 29 2019, 12:15 PM
araujo edited reviewers, added: bhyve; removed: rgrimes.Jan 29 2019, 12:16 PM
araujo edited the summary of this revision. (Show Details)Jan 29 2019, 12:17 PM
araujo added a subscriber: rgrimes.
imp added inline comments.Jan 29 2019, 4:28 PM
usr.sbin/bhyve/bhyverun.c
236

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

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.

araujo updated this revision to Diff 53411.Jan 30 2019, 2:57 AM

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

araujo added inline comments.Jan 30 2019, 2:58 AM
usr.sbin/bhyve/bhyverun.c
236

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

araujo abandoned this revision.Jan 31 2019, 11:33 PM

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

cem added a subscriber: cem.Jun 15 2019, 9:20 PM
cem added inline comments.
usr.sbin/bhyve/bhyverun.c
236

@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.