summaryrefslogtreecommitdiff
path: root/src/xcb_auth.c
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2009-04-07 11:55:30 +0200
committerJulien Danjou <julien@danjou.info>2009-04-10 09:59:49 +0200
commitf0b29819749b769e5a8d313bf1bab80d6513208b (patch)
tree14c1d223f1acdffaaffba9dc5a72335e546eca14 /src/xcb_auth.c
parent9f24c91f91dd68a52e46191b686283b0df38d2f5 (diff)
auth: use snprintf() return value
That save us from a strlen(). Signed-off-by: Julien Danjou <julien@danjou.info>
Diffstat (limited to 'src/xcb_auth.c')
-rw-r--r--src/xcb_auth.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/xcb_auth.c b/src/xcb_auth.c
index a648b16..6e0ff46 100644
--- a/src/xcb_auth.c
+++ b/src/xcb_auth.c
@@ -97,6 +97,7 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
unsigned short family;
char hostnamebuf[256]; /* big enough for max hostname */
char dispbuf[40]; /* big enough to hold more than 2^64 base 10 */
+ int dispbuflen;
family = FamilyLocal; /* 256 */
switch(sockname->sa_family)
@@ -127,7 +128,11 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
return 0; /* cannot authenticate this family */
}
- snprintf(dispbuf, sizeof(dispbuf), "%d", display);
+ dispbuflen = snprintf(dispbuf, sizeof(dispbuf), "%d", display);
+ if(dispbuflen < 0)
+ return 0;
+ /* snprintf may have truncate our text */
+ dispbuflen = MIN(dispbuflen, sizeof(dispbuf) - 1);
if (family == FamilyLocal) {
if (gethostname(hostnamebuf, sizeof(hostnamebuf)) == -1)
@@ -138,7 +143,7 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen,
return XauGetBestAuthByAddr (family,
(unsigned short) addrlen, addr,
- (unsigned short) strlen(dispbuf), dispbuf,
+ (unsigned short) dispbuflen, dispbuf,
N_AUTH_PROTOS, authnames, authnameslen);
}