git: 9d56f34ba29d - stable/13 - hidraw: Return string lengths for certain ioctls
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 26 Dec 2022 21:40:02 UTC
The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=9d56f34ba29df59576e7752b1ab47c380043251c commit 9d56f34ba29df59576e7752b1ab47c380043251c Author: Michael Gmelin <grembo@FreeBSD.org> AuthorDate: 2022-05-17 09:37:21 +0000 Commit: Vladimir Kondratyev <wulf@FreeBSD.org> CommitDate: 2022-12-26 21:37:28 +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. (cherry picked from commit ed87ff4e95d92033d161e93ec1a35ce001638bae) --- 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 e71b2e2c7d5d..8f66775bb791 100644 --- a/sys/dev/hid/hidraw.c +++ b/sys/dev/hid/hidraw.c @@ -517,6 +517,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; @@ -739,10 +740,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): @@ -773,6 +777,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); }