summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2014-01-03 23:07:12 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2014-01-08 17:47:03 -0800
commite5be46eceee9c0c0d5f0363d3e08b19f86f85fcb (patch)
treeb161b65385cf09c94ffa6366866cd7dd07db339b
parente831ef9246684298c147f9b26de0810b8218c3cb (diff)
Use strlcpy instead of strcpy/strncpy if it is available
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac3
-rw-r--r--src/FSErrDis.c5
-rw-r--r--src/FSlibInt.c4
3 files changed, 12 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index bcc4187..26fffb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,6 +51,9 @@ PKG_CHECK_MODULES(FS, xproto >= 7.0.17 fontsproto xtrans)
# Find needed libraries for TCP sockets (pre-pended in $LIBS)
XTRANS_CONNECTION_FLAGS
+# Checks for library functions.
+AC_CHECK_FUNCS([strlcpy])
+
# Allow checking code with lint, sparse, etc.
XORG_WITH_LINT
XORG_LINT_LIBRARY([FS])
diff --git a/src/FSErrDis.c b/src/FSErrDis.c
index 1a712ff..76ebab6 100644
--- a/src/FSErrDis.c
+++ b/src/FSErrDis.c
@@ -84,9 +84,14 @@ int FSGetErrorDatabaseText(
{
if (nbytes == 0)
return 0;
+#ifdef HAVE_STRLCPY
+ if (strlcpy(buffer, defaultp, nbytes) >= nbytes)
+ return 0;
+#else
(void) strncpy(buffer, defaultp, nbytes);
if ((strlen(defaultp) + 1) > nbytes)
buffer[nbytes - 1] = '\0';
+#endif
return 1;
}
diff --git a/src/FSlibInt.c b/src/FSlibInt.c
index 71f6ac1..090da3f 100644
--- a/src/FSlibInt.c
+++ b/src/FSlibInt.c
@@ -850,7 +850,11 @@ _FSPrintDefaultError(
ext && (ext->codes.major_opcode != event->request_code);
ext = ext->next);
if (ext)
+#ifdef HAVE_STRLCPY
+ strlcpy(buffer, ext->name, sizeof(buffer));
+#else
strcpy(buffer, ext->name);
+#endif
else
buffer[0] = '\0';
}