From 99ae57a92dd4f218efe8dbc04cce519efd9d6d5e Mon Sep 17 00:00:00 2001 From: Norbert Thiebaud Date: Sat, 4 Oct 2014 00:51:45 -0500 Subject: [PATCH] hwfilter: fix misuse of strncpy Change-Id: Ia52d6cd32aa3e3838d31ea2a994117e6820a503d --- hwpfilter/source/hwpeq.cxx | 58 ++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/hwpfilter/source/hwpeq.cxx b/hwpfilter/source/hwpeq.cxx index 41c2f3e76904..2cc6ec276485 100644 --- a/hwpfilter/source/hwpeq.cxx +++ b/hwpfilter/source/hwpeq.cxx @@ -404,35 +404,43 @@ static const hwpeq *lookup_eqn(char *str) /* 첫자만 대문자이거나 전부 대문자면 소문자로 바꾼다. */ void make_keyword( char *keyword, const char *token) { - assert(keyword); - char *ptr; - bool result = true; - int len = strlen(token); + char* ptr; + bool result = true; + int len = strlen(token); + assert(keyword); - if( 255 < len ) - strncpy(keyword, token, 255); - else - strcpy(keyword, token); + if( 255 < len ) + { + len = 255; + } + memcpy(keyword, token, len); + keyword[len] = 0; - if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 ) - return; + if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 ) + return; + + int capital = isupper(keyword[1]); + for( ptr = keyword + 2; *ptr && result; ptr++ ) + { + if( (*ptr & 0x80) || + (!capital && isupper(*ptr)) || + (capital && islower(*ptr)) ) + { + result = false; + } + } - int capital = isupper(keyword[1]); - for( ptr = keyword + 2; *ptr && result; ptr++ ) - if( (*ptr & 0x80) || - (!capital && isupper(*ptr)) || - (capital && islower(*ptr)) ) - result = false; - - if( result ) { - ptr = keyword; - while( *ptr ) { - if( isupper(*ptr) ) - *ptr = sal::static_int_cast(tolower(*ptr)); - ptr++; + if( result ) + { + ptr = keyword; + while( *ptr ) + { + if( isupper(*ptr) ) + *ptr = sal::static_int_cast(tolower(*ptr)); + ptr++; + } } - } - return; + return; } // token reading function -- 2.11.4.GIT