• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. 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  * Author: lishunda
13  * Create: 2014-02-25
14  */
15 
16 #include "secinput.h"
17 #if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL && \
18     (!defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT))
19 #include <ctype.h>
20 #endif
21 
22 /*
23  * <NAME>
24  *    vsscanf_s
25  *
26  *
27  * <FUNCTION DESCRIPTION>
28  *    The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by argList
29  *    The vsscanf_s function reads data from buffer into the location given by
30  *    each argument. Every argument must be a pointer to a variable with a type
31  *    that corresponds to a type specifier in format. The format argument controls
32  *    the interpretation of the input fields and has the same form and function
33  *    as the format argument for the scanf function.
34  *    If copying takes place between strings that overlap, the behavior is undefined.
35  *
36  * <INPUT PARAMETERS>
37  *    buffer                Stored data
38  *    format                Format control string, see Format Specifications.
39  *    argList               pointer to list of arguments
40  *
41  * <OUTPUT PARAMETERS>
42  *    argList               the converted value stored in user assigned address
43  *
44  * <RETURN VALUE>
45  *    Each of these functions returns the number of fields successfully converted
46  *    and assigned; the return value does not include fields that were read but
47  *    not assigned. A return value of 0 indicates that no fields were assigned.
48  *    return -1 if an error occurs.
49  */
vsscanf_s(const char * buffer,const char * format,va_list argList)50 int vsscanf_s(const char *buffer, const char *format, va_list argList)
51 {
52     size_t count;               /* If initialization causes  e838 */
53     int retVal;
54     SecFileStream fStr;
55 
56     /* Validation section */
57     if (buffer == NULL || format == NULL) {
58         SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
59         return SECUREC_SCANF_EINVAL;
60     }
61     count = strlen(buffer);
62     if (count == 0 || count > SECUREC_STRING_MAX_LEN) {
63         SecClearDestBuf(buffer, format, argList);
64         SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
65         return SECUREC_SCANF_EINVAL;
66     }
67 #if defined(SECUREC_VXWORKS_PLATFORM) && !SECUREC_IN_KERNEL
68     /*
69      * On vxworks platform when buffer is white string, will set first %s argument tu zero.like following useage:
70      * "   \v\f\t\r\n", "%s", str, strSize
71      * Do not check all character, just first and last character then consider it is white string
72      */
73     if (isspace((int)(unsigned char)buffer[0]) != 0 && isspace((int)(unsigned char)buffer[count - 1]) != 0) {
74         SecClearDestBuf(buffer, format, argList);
75     }
76 #endif
77     SECUREC_FILE_STREAM_FROM_STRING(&fStr, buffer, count);
78     retVal = SecInputS(&fStr, format, argList);
79     if (retVal < 0) {
80         SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
81         return SECUREC_SCANF_EINVAL;
82     }
83     return retVal;
84 }
85 #if SECUREC_IN_KERNEL
86 EXPORT_SYMBOL(vsscanf_s);
87 #endif
88 
89