Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b97c969

Browse files
committed
PyGrammar_LabelRepr(): Conversion of sprintf() to PyOS_snprintf() for
buffer overrun avoidance.
1 parent 58ab084 commit b97c969

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Parser/grammar1.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include "Python.h"
22
/* Grammar subroutines needed by parser */
33

44
#include "pgenheaders.h"
@@ -39,7 +39,7 @@ PyGrammar_LabelRepr(label *lb)
3939
return "EMPTY";
4040
else if (ISNONTERMINAL(lb->lb_type)) {
4141
if (lb->lb_str == NULL) {
42-
sprintf(buf, "NT%d", lb->lb_type);
42+
PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type);
4343
return buf;
4444
}
4545
else
@@ -49,8 +49,9 @@ PyGrammar_LabelRepr(label *lb)
4949
if (lb->lb_str == NULL)
5050
return _PyParser_TokenNames[lb->lb_type];
5151
else {
52-
sprintf(buf, "%.32s(%.32s)",
53-
_PyParser_TokenNames[lb->lb_type], lb->lb_str);
52+
PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)",
53+
_PyParser_TokenNames[lb->lb_type],
54+
lb->lb_str);
5455
return buf;
5556
}
5657
}

0 commit comments

Comments
 (0)