aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorScott Long <scottl@FreeBSD.org>2020-11-14 19:04:36 +0000
committerScott Long <scottl@FreeBSD.org>2020-11-14 19:04:36 +0000
commitbcf9ae275153c1013b88e1332446474242607a80 (patch)
tree7ca800b428f7f972b7216ea3e2af561e02ade7e5 /lib
parentcf82304d7d5e8d9433d46cbdf2db8c2576b85edd (diff)
downloadsrc-bcf9ae275153c1013b88e1332446474242607a80.tar.gz
src-bcf9ae275153c1013b88e1332446474242607a80.zip
Fix a problem with r367686 related to the use of ssize_t. Not sure how this
escaped prior testing, but it should be better now. Reported by: lots
Notes
Notes: svn path=/head/; revision=367689
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/getlocalbase.c13
-rw-r--r--lib/libutil/libutil.h5
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/libutil/getlocalbase.c b/lib/libutil/getlocalbase.c
index 88cf3f472d9c..0286a9cf014f 100644
--- a/lib/libutil/getlocalbase.c
+++ b/lib/libutil/getlocalbase.c
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/sysctl.h>
+#include <sys/limits.h>
#include <stdlib.h>
#include <paths.h>
#include <libutil.h>
@@ -66,10 +67,16 @@ getlocalbase(char *path, size_t pathlen)
#endif
tmplen = strlcpy(path, tmppath, pathlen);
- if ((tmplen < 0) || (tmplen >= (ssize_t)pathlen)) {
+ if ((tmplen < 0) || (tmplen >= pathlen)) {
errno = ENOMEM;
- tmplen = -1;
+ return (-1);
+ }
+
+ /* It's unlikely that the buffer would be this big */
+ if (tmplen >= SSIZE_MAX) {
+ errno = ENOMEM;
+ return (-1);
}
- return (tmplen);
+ return ((ssize_t)tmplen);
}
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index 8f093b59af51..1c72f599f7dd 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -65,6 +65,11 @@ typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
+#ifndef _SSIZE_T_DECLARED
+typedef __ssize_t ssize_t;
+#define _SSIZE_T_DECLARED
+#endif
+
#ifndef _UID_T_DECLARED
typedef __uid_t uid_t;
#define _UID_T_DECLARED