git: ed87ff4e95d9 - main - hidraw: Return string lengths for certain ioctls
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 18 May 2022 10:13:10 UTC
The branch main has been updated by grembo (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=ed87ff4e95d92033d161e93ec1a35ce001638bae commit ed87ff4e95d92033d161e93ec1a35ce001638bae Author: Michael Gmelin <grembo@FreeBSD.org> AuthorDate: 2022-05-17 09:37:21 +0000 Commit: Michael Gmelin <grembo@FreeBSD.org> CommitDate: 2022-05-18 10:12:19 +0000 hidraw: Return string lengths for certain ioctls Make HIDIOCGRAWPHYS, HIDIOCGRAWNAME, and HIDIOCGRAWUNIQ return the length of the copied out string (including the trailing NUL character), so they behave like their Linux hidraw counterparts. Reviewed by: wulf Differential Revision: https://reviews.freebsd.org/D35233 --- sys/dev/hid/hidraw.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/dev/hid/hidraw.c b/sys/dev/hid/hidraw.c index c8e36a186aaf..8964e31f7bba 100644 --- a/sys/dev/hid/hidraw.c +++ b/sys/dev/hid/hidraw.c @@ -569,6 +569,7 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct hidraw_gen_descriptor *hgd; struct hidraw_report_descriptor *hrd; struct hidraw_devinfo *hdi; + const char *devname; uint32_t size; int id, len; int error = 0; @@ -825,10 +826,13 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, switch (IOCBASECMD(cmd)) { case HIDIOCGRAWNAME(0): strlcpy(addr, sc->sc_hw->name, len); + td->td_retval[0] = min(strlen(sc->sc_hw->name) + 1, len); return (0); case HIDIOCGRAWPHYS(0): - strlcpy(addr, device_get_nameunit(sc->sc_dev), len); + devname = device_get_nameunit(sc->sc_dev); + strlcpy(addr, devname, len); + td->td_retval[0] = min(strlen(devname) + 1, len); return (0); case HIDIOCSFEATURE(0): @@ -859,6 +863,7 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, case HIDIOCGRAWUNIQ(0): strlcpy(addr, sc->sc_hw->serial, len); + td->td_retval[0] = min(strlen(sc->sc_hw->serial) + 1, len); return (0); }