mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
Fixes sscan %sn where strlen(data) < n
This commit is contained in:
+14
-7
@@ -164,7 +164,7 @@ int sscanf(FAR const char *buf, FAR const char *fmt, ...)
|
|||||||
* ANSI standard vsscanf implementation.
|
* ANSI standard vsscanf implementation.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#pragma GCC optimize ("O0")
|
||||||
int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
FAR const char *bufstart;
|
FAR const char *bufstart;
|
||||||
@@ -174,6 +174,7 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
|||||||
bool noassign;
|
bool noassign;
|
||||||
int count;
|
int count;
|
||||||
int width;
|
int width;
|
||||||
|
int fwidth;
|
||||||
int base = 10;
|
int base = 10;
|
||||||
char tmp[MAXLN];
|
char tmp[MAXLN];
|
||||||
|
|
||||||
@@ -275,16 +276,22 @@ int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap)
|
|||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Was a fieldwidth specified? */
|
/* Guess a field width using some heuristics */
|
||||||
|
|
||||||
if (!width)
|
fwidth = findwidth(buf, fmt);
|
||||||
|
|
||||||
|
/* Use the actual field's width if 1) no fieldwidth
|
||||||
|
* specified or 2) the actual field's width is smaller
|
||||||
|
* than fieldwidth specified
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!width || fwidth < width)
|
||||||
{
|
{
|
||||||
/* No... Guess a field width using some heuristics */
|
width = fwidth;
|
||||||
|
|
||||||
int tmpwidth = findwidth(buf, fmt);
|
|
||||||
width = MIN(sizeof(tmp) - 1, tmpwidth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
width = MIN(sizeof(tmp) - 1, width);
|
||||||
|
|
||||||
/* Copy the string (if we are making an assignment) */
|
/* Copy the string (if we are making an assignment) */
|
||||||
|
|
||||||
if (!noassign)
|
if (!noassign)
|
||||||
|
|||||||
Reference in New Issue
Block a user