1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2014-2021. All rights reserved.
3 * Licensed under Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 * http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 * Description: vsscanf_s function
12 * Create: 2014-02-25
13 */
14
15 #include "secinput.h"
16 #if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL && \
17 (!defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT))
18 #include <ctype.h>
19 #endif
20
21 /*
22 * <NAME>
23 * vsscanf_s
24 *
25 *
26 * <FUNCTION DESCRIPTION>
27 * The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by argList
28 * The vsscanf_s function reads data from buffer into the location given by
29 * each argument. Every argument must be a pointer to a variable with a type
30 * that corresponds to a type specifier in format. The format argument controls
31 * the interpretation of the input fields and has the same form and function
32 * as the format argument for the scanf function.
33 * If copying takes place between strings that overlap, the behavior is undefined.
34 *
35 * <INPUT PARAMETERS>
36 * buffer Stored data
37 * format Format control string, see Format Specifications.
38 * argList pointer to list of arguments
39 *
40 * <OUTPUT PARAMETERS>
41 * argList the converted value stored in user assigned address
42 *
43 * <RETURN VALUE>
44 * Each of these functions returns the number of fields successfully converted
45 * and assigned; the return value does not include fields that were read but
46 * not assigned. A return value of 0 indicates that no fields were assigned.
47 * return -1 if an error occurs.
48 */
vsscanf_s(const char * buffer,const char * format,va_list argList)49 int vsscanf_s(const char *buffer, const char *format, va_list argList)
50 {
51 size_t count; /* If initialization causes e838 */
52 int retVal;
53 SecFileStream fStr;
54
55 /* Validation section */
56 if (buffer == NULL || format == NULL) {
57 SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
58 return SECUREC_SCANF_EINVAL;
59 }
60 count = strlen(buffer);
61 if (count == 0 || count > SECUREC_STRING_MAX_LEN) {
62 SecClearDestBuf(buffer, format, argList);
63 SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
64 return SECUREC_SCANF_EINVAL;
65 }
66 #if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL
67 /*
68 * On vxworks platform when buffer is white string, will set first %s argument to zero.Like following usage:
69 * " \v\f\t\r\n", "%s", str, strSize
70 * Do not check all character, just first and last character then consider it is white string
71 */
72 if (isspace((int)(unsigned char)buffer[0]) != 0 && isspace((int)(unsigned char)buffer[count - 1]) != 0) {
73 SecClearDestBuf(buffer, format, argList);
74 }
75 #endif
76 SECUREC_FILE_STREAM_FROM_STRING(&fStr, buffer, count);
77 retVal = SecInputS(&fStr, format, argList);
78 if (retVal < 0) {
79 SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
80 return SECUREC_SCANF_EINVAL;
81 }
82 return retVal;
83 }
84 #if SECUREC_EXPORT_KERNEL_SYMBOL
85 EXPORT_SYMBOL(vsscanf_s);
86 #endif
87
88