• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "secinput.h"
17 #if defined(SECUREC_VXWORKS_PLATFORM) && !defined(SECUREC_SYSAPI4VXWORKS)
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  *******************************************************************************
49  */
50 #ifndef __MINGW32__
vsscanf_s(const char * buffer,const char * format,va_list arglist)51 int vsscanf_s(const char *buffer, const char *format, va_list arglist)
52 {
53     SecFileStream fStr = SECUREC_INIT_SEC_FILE_STREAM;
54     int retVal;                 /* If initialization causes  e838 */
55     size_t count;               /* If initialization causes  e838 */
56 
57     /* validation section */
58     if (buffer == NULL || format == NULL) {
59         SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
60         return SECUREC_SCANF_EINVAL;
61     }
62     count = strlen(buffer);
63     if (count == 0 || count > SECUREC_STRING_MAX_LEN) {
64         SecClearDestBuf(buffer, format, arglist);
65         SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
66         return SECUREC_SCANF_EINVAL;
67     }
68 #ifdef SECUREC_VXWORKS_PLATFORM
69     if (isspace((int)buffer[0]) && isspace((int)buffer[count - 1])) {
70         SecClearDestBuf(buffer, format, arglist);
71     }
72 #endif
73     fStr.flag = SECUREC_MEM_STR_FLAG;
74     fStr.cur = (const char *)buffer;
75     fStr.count = (int)count;
76     retVal = SecInputS(&fStr, format, arglist);
77     if (retVal < 0) {
78         SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
79         return SECUREC_SCANF_EINVAL;
80     }
81 
82     return retVal;
83 }
84 #endif
85 
86