diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2016-09-25 22:34:27 +0200 |
---|---|---|
committer | Matthieu Herrb <matthieu@herrb.eu> | 2016-09-25 22:34:27 +0200 |
commit | 2cd95e7da8367cccdcdd5c9b160012d1dec5cbdb (patch) | |
tree | 7c226e0f4b18b8ca3e729a44ed98860d7de68839 /src | |
parent | ab0d28935987d48e9359023e82f9d56aa7e4bc95 (diff) |
Avoid buffer underflow on empty strings.
If an empty string is received from an x-server, do not underrun the
buffer by accessing "rep.nameLen - 1" unconditionally, which could end
up being -1.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
Diffstat (limited to 'src')
-rw-r--r-- | src/XvMC.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -576,9 +576,9 @@ Status XvMCGetDRInfo(Display *dpy, XvPortID port, if (*name && *busID && tmpBuf) { _XRead(dpy, tmpBuf, realSize); strncpy(*name,tmpBuf,rep.nameLen); - (*name)[rep.nameLen - 1] = '\0'; + (*name)[rep.nameLen == 0 ? 0 : rep.nameLen - 1] = '\0'; strncpy(*busID,tmpBuf+rep.nameLen,rep.busIDLen); - (*busID)[rep.busIDLen - 1] = '\0'; + (*busID)[rep.busIDLen == 0 ? 0 : rep.busIDLen - 1] = '\0'; XFree(tmpBuf); } else { XFree(*name); |