[Python-checkins] CVS: python/dist/src/Python compile.c,2.231,2.232

Barry Warsaw bwarsaw@users.sourceforge.net
2001年11月28日 13:10:43 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv18695
Modified Files:
	compile.c 
Log Message:
code_repr(), com_addop_varname(), com_list_comprehension(),
com_arglist(), symtable_check_unoptimized(), symtable_params(),
symtable_global(), symtable_list_comprehension():
 Conversion of sprintf() to PyOS_snprintf() for buffer overrun
 avoidance.
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.231
retrieving revision 2.232
diff -C2 -d -r2.231 -r2.232
*** compile.c	2001年11月28日 11:47:00	2.231
--- compile.c	2001年11月28日 21:10:39	2.232
***************
*** 121,126 ****
 	if (co->co_name && PyString_Check(co->co_name))
 		name = PyString_AS_STRING(co->co_name);
! 	sprintf(buf, "<code object %.100s at %p, file \"%.300s\", line %d>",
! 		name, co, filename, lineno);
 	return PyString_FromString(buf);
 }
--- 121,127 ----
 	if (co->co_name && PyString_Check(co->co_name))
 		name = PyString_AS_STRING(co->co_name);
! 	PyOS_snprintf(buf, sizeof(buf),
! 		 "<code object %.100s at %p, file \"%.300s\", line %d>",
! 		 name, co, filename, lineno);
 	return PyString_FromString(buf);
 }
***************
*** 1021,1025 ****
 		case NAME_CLOSURE: {
 			char buf[500];
! 			sprintf(buf, DEL_CLOSURE_ERROR, name);
 			com_error(c, PyExc_SyntaxError, buf);
 			i = 255;
--- 1022,1027 ----
 		case NAME_CLOSURE: {
 			char buf[500];
! 			PyOS_snprintf(buf, sizeof(buf),
! 				 DEL_CLOSURE_ERROR, name);
 			com_error(c, PyExc_SyntaxError, buf);
 			i = 255;
***************
*** 1367,1372 ****
 {
 	/* listmaker: test list_for */
! 	char tmpname[12];
! 	sprintf(tmpname, "_[%d]", ++c->c_tmpname);
 	com_addoparg(c, BUILD_LIST, 0);
 	com_addbyte(c, DUP_TOP); /* leave the result on the stack */
--- 1369,1374 ----
 {
 	/* listmaker: test list_for */
! 	char tmpname[30];
! 	PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", ++c->c_tmpname);
 	com_addoparg(c, BUILD_LIST, 0);
 	com_addbyte(c, DUP_TOP); /* leave the result on the stack */
***************
*** 3790,3794 ****
 	int nch, i, narg;
 	int complex = 0;
! 	char nbuf[10];
 	REQ(n, varargslist);
 	/* varargslist:
--- 3792,3796 ----
 	int nch, i, narg;
 	int complex = 0;
! 	char nbuf[30];
 	REQ(n, varargslist);
 	/* varargslist:
***************
*** 3804,3808 ****
 		fp = CHILD(ch, 0);
 		if (TYPE(fp) != NAME) {
! 			sprintf(nbuf, ".%d", i);
 			complex = 1;
 		}
--- 3806,3810 ----
 		fp = CHILD(ch, 0);
 		if (TYPE(fp) != NAME) {
! 			PyOS_snprintf(nbuf, sizeof(nbuf), ".%d", i);
 			complex = 1;
 		}
***************
*** 4456,4484 ****
 	if (ste->ste_child_free) {
 		if (ste->ste_optimized == OPT_IMPORT_STAR)
! 			sprintf(buf, ILLEGAL_IMPORT_STAR, 
! 				PyString_AS_STRING(ste->ste_name),
! 				ILLEGAL_CONTAINS);
 		else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC))
! 			sprintf(buf, ILLEGAL_BARE_EXEC,
! 				PyString_AS_STRING(ste->ste_name),
! 				ILLEGAL_CONTAINS);
 		else {
! 			sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR,
! 				PyString_AS_STRING(ste->ste_name),
! 				ILLEGAL_CONTAINS);
 		}
 	} else {
 		if (ste->ste_optimized == OPT_IMPORT_STAR)
! 			sprintf(buf, ILLEGAL_IMPORT_STAR, 
! 				PyString_AS_STRING(ste->ste_name),
! 				ILLEGAL_IS);
 		else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC))
! 			sprintf(buf, ILLEGAL_BARE_EXEC,
! 				PyString_AS_STRING(ste->ste_name),
! 				ILLEGAL_IS);
 		else {
! 			sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR,
! 				PyString_AS_STRING(ste->ste_name),
! 				ILLEGAL_IS);
 		}
 	}
--- 4458,4492 ----
 	if (ste->ste_child_free) {
 		if (ste->ste_optimized == OPT_IMPORT_STAR)
! 			PyOS_snprintf(buf, sizeof(buf),
! 				 ILLEGAL_IMPORT_STAR, 
! 				 PyString_AS_STRING(ste->ste_name),
! 				 ILLEGAL_CONTAINS);
 		else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC))
! 			PyOS_snprintf(buf, sizeof(buf),
! 				 ILLEGAL_BARE_EXEC,
! 				 PyString_AS_STRING(ste->ste_name),
! 				 ILLEGAL_CONTAINS);
 		else {
! 			PyOS_snprintf(buf, sizeof(buf),
! 				 ILLEGAL_EXEC_AND_IMPORT_STAR,
! 				 PyString_AS_STRING(ste->ste_name),
! 				 ILLEGAL_CONTAINS);
 		}
 	} else {
 		if (ste->ste_optimized == OPT_IMPORT_STAR)
! 			PyOS_snprintf(buf, sizeof(buf),
! 				 ILLEGAL_IMPORT_STAR, 
! 				 PyString_AS_STRING(ste->ste_name),
! 				 ILLEGAL_IS);
 		else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC))
! 			PyOS_snprintf(buf, sizeof(buf),
! 				 ILLEGAL_BARE_EXEC,
! 				 PyString_AS_STRING(ste->ste_name),
! 				 ILLEGAL_IS);
 		else {
! 			PyOS_snprintf(buf, sizeof(buf),
! 				 ILLEGAL_EXEC_AND_IMPORT_STAR,
! 				 PyString_AS_STRING(ste->ste_name),
! 				 ILLEGAL_IS);
 		}
 	}
***************
*** 5232,5237 ****
 			symtable_add_def(st, STR(CHILD(c, 0)), DEF_PARAM);
 		else {
! 			char nbuf[10];
! 			sprintf(nbuf, ".%d", i);
 			symtable_add_def(st, nbuf, DEF_PARAM);
 			complex = i;
--- 5240,5245 ----
 			symtable_add_def(st, STR(CHILD(c, 0)), DEF_PARAM);
 		else {
! 			char nbuf[30];
! 			PyOS_snprintf(nbuf, sizeof(nbuf), ".%d", i);
 			symtable_add_def(st, nbuf, DEF_PARAM);
 			complex = i;
***************
*** 5319,5326 ****
 			else {
 				if (flags & DEF_LOCAL)
! 					sprintf(buf, GLOBAL_AFTER_ASSIGN,
! 						name);
 				else
! 					sprintf(buf, GLOBAL_AFTER_USE, name);
 				symtable_warn(st, buf);
 			}
--- 5327,5336 ----
 			else {
 				if (flags & DEF_LOCAL)
! 					PyOS_snprintf(buf, sizeof(buf),
! 						 GLOBAL_AFTER_ASSIGN,
! 						 name);
 				else
! 					PyOS_snprintf(buf, sizeof(buf),
! 						 GLOBAL_AFTER_USE, name);
 				symtable_warn(st, buf);
 			}
***************
*** 5333,5339 ****
 symtable_list_comprehension(struct symtable *st, node *n)
 {
! 	char tmpname[12];
 
! 	sprintf(tmpname, "_[%d]", st->st_tmpname);
 	symtable_add_def(st, tmpname, DEF_LOCAL);
 	symtable_assign(st, CHILD(n, 1), 0);
--- 5343,5349 ----
 symtable_list_comprehension(struct symtable *st, node *n)
 {
! 	char tmpname[30];
 
! 	PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", st->st_tmpname);
 	symtable_add_def(st, tmpname, DEF_LOCAL);
 	symtable_assign(st, CHILD(n, 1), 0);

AltStyle によって変換されたページ (->オリジナル) /