From: Fariborz Jahanian Date: Sat, 24 Oct 2009 00:16:42 +0000 (+0000) Subject: Make the local buffer overflow safe. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d0d85c3370f2726c74ba0ece0a5e712830a1d82;p=clang Make the local buffer overflow safe. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84981 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index e226f28c86..eb09d9ecce 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2854,11 +2854,10 @@ QualType ASTContext::BuildByRefType(const char *DeclName, QualType Ty) { bool HasCopyAndDispose = BlockRequiresCopying(Ty); // FIXME: Move up - static int UniqueBlockByRefTypeID = 0; - // FIXME. This is error prone. Luckinly stack-canary stuff caught it. - char Name[128]; + static unsigned int UniqueBlockByRefTypeID = 0; + char * Name = + (char*)alloca(strlen("__Block_byref_") + 10 + 1 + strlen(DeclName) + 1); sprintf(Name, "__Block_byref_%d_%s", ++UniqueBlockByRefTypeID, DeclName); - assert((strlen(Name) < sizeof(Name)) && "BuildByRefType - buffer overflow"); RecordDecl *T; T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), &Idents.get(Name)); @@ -2905,11 +2904,10 @@ QualType ASTContext::getBlockParmType( bool BlockHasCopyDispose, llvm::SmallVector &BlockDeclRefDecls) { // FIXME: Move up - static int UniqueBlockParmTypeID = 0; - // FIXME. This is error prone. Luckinly stack-canary stuff caught it. - char Name[128]; + static unsigned int UniqueBlockParmTypeID = 0; + char * Name = + (char*)alloca(strlen("__block_literal_") + 10 + 1); sprintf(Name, "__block_literal_%u", ++UniqueBlockParmTypeID); - assert((strlen(Name) < sizeof(Name)) && "getBlockParmType - buffer overflow"); RecordDecl *T; T = RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), &Idents.get(Name));