safec: update to ugw 8.4.1.30

This commit is contained in:
Oussama Ghorbel
2020-02-04 17:04:45 +01:00
parent 9ae1748f11
commit b7ee667dcd
2 changed files with 340 additions and 7 deletions

View File

@@ -7,17 +7,16 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=libsafec
PKG_VERSION:=10052013
PKG_VERSION:=v10052013
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=http://git.code.sf.net/p/safeclib/code
PKG_SOURCE_URL:=https://github.com/rurban/safeclib.git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=88a3bf7c7e4cd6f0b7a8559050523bacb31362f3
PKG_SOURCE_VERSION:=v10052013
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_MAINTAINER:=Bo Berry <bberryusa@users.sourceforge.net>
PKG_MD5SUM:=440c5581d40049a195e8bcc5c4dc8aff
PKG_MIRROR_MD5SUM:=xxx
PKG_MIRROR_HASH:=aa14466f7f6d6cb1518e5334cbd72d132ca5a8cec71f396457560e7fd939d662
PKG_LICENSE:=CISCO SYSTEMS
PKG_LICENSE_FILES:=COPYING
@@ -37,8 +36,8 @@ define Package/safeclibs/default
SECTION:=libs
CATEGORY:=Libraries
PROVIDES:=libsafec
URL:=http://sourceforge.net/projects/safeclib
VERSION:=10052013
URL:=https://github.com/rurban/safeclib.git
VERSION:=v10052013
endef
define Package/safeclibs

View File

@@ -0,0 +1,334 @@
diff --git a/Kbuild b/Kbuild
index 4000301..64d95ee 100644
--- a/Kbuild
+++ b/Kbuild
@@ -75,6 +75,8 @@ slkm-y += src/safeclib/strnlen_s.o
slkm-y += src/safeclib/strpbrk_s.o
slkm-y += src/safeclib/strspn_s.o
slkm-y += src/safeclib/strcspn_s.o
+slkm-y += src/safeclib/vsscanf_s.o
+slkm-y += src/safeclib/sscanf_s.o
testslkm-y := tests/test_slkm.o
testslkm-y += tests/test_memset_s.o
diff --git a/include/safe_str_lib.h b/include/safe_str_lib.h
index e71f133..88e31be 100644
--- a/include/safe_str_lib.h
+++ b/include/safe_str_lib.h
@@ -260,6 +260,11 @@ strtouppercase_s(char *str, rsize_t slen);
extern errno_t
strzero_s(char *dest, rsize_t dmax);
+extern int
+vsscanf_s(const char *dest, const char *fmt, va_list ap);
+
+extern int
+sscanf_s(const char *buffer, const char *fmt, ...);
#ifdef __cplusplus
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 0eda771..d72dd8e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,7 +65,9 @@ STD_STR_FILES = \
safeclib/strncat_s.c \
safeclib/strcpy_s.c \
safeclib/strncpy_s.c \
- safeclib/strtok_s.c
+ safeclib/strtok_s.c \
+ safeclib/vsscanf_s.c \
+ safeclib/sscanf_s.c
EXT_STR_FILES = \
safeclib/strcmp_s.c \
diff --git a/src/safeclib/sscanf_s.c b/src/safeclib/sscanf_s.c
new file mode 100644
index 0000000..4964fb0
--- /dev/null
+++ b/src/safeclib/sscanf_s.c
@@ -0,0 +1,141 @@
+/*------------------------------------------------------------------
+ * sscanf_s.c
+ *
+ * September 2017, Reini Urban
+ *
+ * Copyright (c) 2017 by Reini Urban
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *------------------------------------------------------------------
+ */
+
+#include <stdarg.h>
+#include "safeclib_private.h"
+#include "safe_str_constraint.h"
+#include "safe_str_lib.h"
+
+/* TODO:
+any of the arguments corresponding to %s is a null pointer.
+*/
+
+/**
+ * @brief
+ * The \c sscanf_s function reads a formatted string, and writes
+ * to a list of arguments.
+ * Reaching the end of the string is equivalent to reaching the
+ * end-of-file condition for \c fscanf.
+ *
+ * @remark SPECIFIED IN
+ * * C11 standard (ISO/IEC 9899:2011):
+ * K.3.5.3.7 The sscanf_s function (p: 596)
+ * http://en.cppreference.com/w/c/io/fscanf
+ *
+ * @param[in] buffer pointer to a null-terminated string to read from
+ * @param[in] fmt format-control string.
+ * @param[out] ... arguments to write to
+ *
+ * @pre Neither \c buffer nor \c fmt shall be a null pointer.
+ * @pre \c fmt shall not contain the conversion specifier \c %n
+ * @pre None of the arguments corresponding to \c %s is a null pointer. (not yet)
+ * @pre No encoding error shall occur.
+ * @pre \c %c, \c %s, and \c %[ conversion specifiers each expect two
+ * arguments (the usual pointer and a value of type \c rsize_t
+ * indicating the size of the receiving array, which may be 1
+ * when reading with a \c %c into a single character) and
+ * except that the following errors are detected at runtime and
+ * call the currently installed constraint handler function.
+ *
+ * @return Number of receiving arguments successfully assigned, or \c EOF
+ * if read failure occurs before the first receiving argument
+ * was assigned or if there is a runtime constraint
+ * violation.
+ *
+ * @retval > 0 on success, the number of arguments assigned
+ * @retval EOF on error
+ *
+ * @see
+ * vsscanf_s(), swscanf_s(), vsnprintf_s()
+ *
+ */
+
+#define _expect(expr,value) (expr)
+#define unlikely(expr) _expect ((long)((expr) != 0), 0)
+
+int
+sscanf_s(const char *buffer, const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+#if defined(HAVE_STRSTR)
+ char *p;
+#endif
+
+ if (unlikely(buffer == NULL)) {
+ invoke_safe_str_constraint_handler("sscanf_s: buffer is null",
+ NULL, ESNULLP);
+ errno = ESNULLP;
+ return EOF;
+ }
+
+ if (unlikely(fmt == NULL)) {
+ invoke_safe_str_constraint_handler("sscanf_s: fmt is null",
+ NULL, ESNULLP);
+ errno = ESNULLP;
+ return EOF;
+ }
+
+#if defined(HAVE_STRSTR)
+ if (unlikely((p = strstr((char*)fmt, "%n")))) {
+ if ((p-fmt == 0) || *(p-1) != '%') {
+ invoke_safe_str_constraint_handler("sscanf_s: illegal %n",
+ NULL, EINVAL);
+ errno = EINVAL;
+ return EOF;
+ }
+ }
+#elif defined(HAVE_STRCHR)
+ if (unlikely((p = strchr(fmt, flen, 'n')))) {
+ /* at the beginning or if inside, not %%n */
+ if (((p-fmt >= 1) && *(p-1) == '%') &&
+ ((p-fmt == 1) || *(p-2) != '%')) {
+ invoke_safe_str_constraint_handler("sscanf_s: illegal %n",
+ NULL, EINVAL);
+ errno = EINVAL;
+ return EOF;
+ }
+ }
+#endif
+
+ errno = 0;
+ va_start(ap, fmt);
+ ret = vsscanf(buffer, fmt, ap);
+ va_end(ap);
+
+ if (unlikely(ret < 0)) { /* always -1 EOF */
+ char errstr[128] = "sscanf_s: ";
+ strcat(errstr, strerror(errno));
+ invoke_safe_str_constraint_handler(errstr, NULL, errno);
+ }
+
+ return ret;
+}
diff --git a/src/safeclib/vsscanf_s.c b/src/safeclib/vsscanf_s.c
new file mode 100644
index 0000000..398a814
--- /dev/null
+++ b/src/safeclib/vsscanf_s.c
@@ -0,0 +1,137 @@
+/*------------------------------------------------------------------
+ * vsscanf_s.c
+ *
+ * September 2017, Reini Urban
+ *
+ * Copyright (c) 2017 by Reini Urban
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *------------------------------------------------------------------
+ */
+
+#include <stdarg.h>
+#include "safeclib_private.h"
+#include "safe_str_constraint.h"
+#include "safe_str_lib.h"
+
+/* TODO:
+any of the arguments corresponding to %s is a null pointer.
+*/
+
+/**
+ * @brief
+ * The \c vsscanf_s function reads a formatted string, and writes
+ * to a list of arguments.
+ * Reaching the end of the string is equivalent to reaching the
+ * end-of-file condition for \c fscanf.
+ *
+ * @remark SPECIFIED IN
+ * * C11 standard (ISO/IEC 9899:2011):
+ * K.3.5.3.14 The vsscanf_s function (p: 602)
+ * http://en.cppreference.com/w/c/io/vfscanf
+ *
+ * @param[in] buffer pointer to a null-terminated string to read from
+ * @param[in] fmt format-control string.
+ * @param[out] ap arguments to write to
+ *
+ * @pre Neither \c buffer nor \c fmt shall be a null pointer.
+ * @pre \c fmt shall not contain the conversion specifier \c %n
+ * @pre None of the arguments corresponding to \c %s is a null pointer. (not yet)
+ * @pre No encoding error shall occur.
+ * @pre \c %c, \c %s, and \c %[ conversion specifiers each expect two
+ * arguments (the usual pointer and a value of type \c rsize_t
+ * indicating the size of the receiving array, which may be 1
+ * when reading with a \c %c into a single character) and
+ * except that the following errors are detected at runtime and
+ * call the currently installed constraint handler function.
+ *
+ * @return Number of receiving arguments successfully assigned, or \c EOF
+ * if read failure occurs before the first receiving argument
+ * was assigned or if there is a runtime constraint
+ * violation.
+ *
+ * @retval > 0 on success, the number of arguments assigned
+ * @retval EOF on error
+ *
+ * @see
+ * vvsscanf_s(), swscanf_s(), vsnprintf_s()
+ *
+ */
+#define _expect(expr,value) (expr)
+#define unlikely(expr) _expect ((long)((expr) != 0), 0)
+
+int
+vsscanf_s(const char *buffer, const char *fmt, va_list ap)
+{
+#if defined(HAVE_STRSTR)
+ char *p;
+#endif
+ int ret;
+
+ if (unlikely(buffer == NULL)) {
+ invoke_safe_str_constraint_handler("vsscanf_s: buffer is null",
+ NULL, ESNULLP);
+ errno = ESNULLP;
+ return EOF;
+ }
+
+ if (unlikely(fmt == NULL)) {
+ invoke_safe_str_constraint_handler("vsscanf_s: fmt is null",
+ NULL, ESNULLP);
+ errno = ESNULLP;
+ return EOF;
+ }
+
+#if defined(HAVE_STRSTR)
+ if (unlikely((p = strstr((char*)fmt, "%n")))) {
+ if ((p-fmt == 0) || *(p-1) != '%') {
+ invoke_safe_str_constraint_handler("vsscanf_s: illegal %n",
+ NULL, EINVAL);
+ errno = EINVAL;
+ return EOF;
+ }
+ }
+#elif defined(HAVE_STRCHR)
+ if (unlikely((p = strchr(fmt, flen, 'n')))) {
+ /* at the beginning or if inside, not %%n */
+ if (((p-fmt >= 1) && *(p-1) == '%') &&
+ ((p-fmt == 1) || *(p-2) != '%')) {
+ invoke_safe_str_constraint_handler("vsscanf_s: illegal %n",
+ NULL, EINVAL);
+ errno = EINVAL;
+ return EOF;
+ }
+ }
+#endif
+
+ errno = 0;
+ ret = vsscanf(buffer, fmt, ap);
+
+ if (unlikely(ret < 0)) { /* always -1 EOF */
+ char errstr[128] = "vsscanf_s: ";
+ strcat(errstr, strerror(errno));
+ invoke_safe_str_constraint_handler(errstr, NULL, errno);
+ }
+
+ return ret;
+}