OSDN Git Service

Ver.1.5.33 changed strncpy/cat to strlcpy/cat
authorwatanaby <watanaby@is.saga-u.ac.jp>
Mon, 29 Sep 2014 03:44:43 +0000 (12:44 +0900)
committerwatanaby <watanaby@is.saga-u.ac.jp>
Mon, 29 Sep 2014 03:44:43 +0000 (12:44 +0900)
19 files changed:
opengate/doc/Changes.html
opengate/opengatesrv/addr-convert.c
opengate/opengatesrv/auth-ldap.c
opengate/opengatesrv/auth-pam.c
opengate/opengatesrv/comm-arp.c
opengate/opengatesrv/comm-auth.c
opengate/opengatesrv/comm-cgi.c
opengate/opengatesrv/comm-ndp.c
opengate/opengatesrv/comm-userdb.c
opengate/opengatesrv/ctrl-alarms.c
opengate/opengatesrv/ctrl-firewall.c
opengate/opengatesrv/get-param.c
opengate/opengatesrv/htmltemplate.c
opengate/opengatesrv/opengateauth.c
opengate/opengatesrv/opengatefwd.c
opengate/opengatesrv/test-comm-ipfw.c
opengate/opengatesrv/test-watch-client.c
opengate/opengatesrv/utilities.c
opengate/opengatesrv/watch-client.c

index f747113..18c448b 100644 (file)
@@ -772,9 +772,10 @@ Opengate History</H3>
        Fixed error to ingore duration value in extra set.
        </DD>
        <DT>
-       Ver.1.5.33 at 2014.9.26
+       Ver.1.5.33 at 2014.9.29
        </DT><DD>
        Added checking of null language string.
+       Changed strncpy/strncat to strlcpy/strlcat.
        </DD>
        </DL>
 <P>
index 4320e49..40a2158 100644 (file)
@@ -57,7 +57,7 @@ int addrEncode(char encodeAddr[], char dotSepAddr[])
     snprintf(encodeAddr, ADDRMAXLN,
             "%lu-%d-%d", address,checkDigit, (int)time(NULL));
   }else{
-    strncpy(encodeAddr, "0-0-0", ADDRMAXLN);
+    strlcpy(encodeAddr, "0-0-0", ADDRMAXLN);
   }
 
   return illform;
index 9c8be97..3e6d2fb 100644 (file)
@@ -85,9 +85,9 @@ int authLdap(char *userid, char *passwd)
   }
   
   /* set filter */
-  strncpy(filter, "(uid=", BUFFMAXLN);
-  strncat(filter, userid, BUFFMAXLN);
-  strncat(filter, ")", BUFFMAXLN);
+  strlcpy(filter, "(uid=", BUFFMAXLN);
+  strlcat(filter, userid, BUFFMAXLN);
+  strlcat(filter, ")", BUFFMAXLN);
   
   /* search LDAP entry */
   ret = ldap_search_ext_s(ld,baseDn,LDAP_SCOPE_SUBTREE,
index bebca02..008d780 100644 (file)
@@ -57,9 +57,9 @@ int authPam(char *userid, char *passwd)
   serviceNameInConf=GetConfValue("AuthServer/ServiceName");
 
   if(isNull(serviceNameInConf)){
-    strncpy(serviceName, PAMSERVICENAME, ADDRMAXLN);
+    strlcpy(serviceName, PAMSERVICENAME, ADDRMAXLN);
   }else{
-    strncpy(serviceName, serviceNameInConf, ADDRMAXLN);
+    strlcpy(serviceName, serviceNameInConf, ADDRMAXLN);
   }
   
   if(!userid || !passwd) return DENY;
index ba404c5..f8a6c20 100644 (file)
@@ -69,7 +69,7 @@ int getMacAddrFromArp(char *clientAddr4, char* macAddr4)
   if((strstr(startp, ":"))==NULL) return -1;
 
   /* save to macAddr4 */
-  strncpy(macAddr4, startp, ADDRMAXLN);
+  strlcpy(macAddr4, startp, ADDRMAXLN);
     
   return 0;
 }
index 9e227f2..f2399b3 100644 (file)
@@ -136,19 +136,19 @@ void splitId(char* userid, char* useridshort, char* extraId)
 
   char* markPnt=NULL;
 
-  strncpy(useridSave, userid, USERMAXLN);
+  strlcpy(useridSave, userid, USERMAXLN);
 
   /* separate extraId from userid at separator(@) */
   markPnt=strchr(useridSave, *GetConfValue("UserIdSeparator"));
   if(markPnt==NULL){  
     /* separator mark not found */
-    strncpy(extraId,"",USERMAXLN);
-    strncpy(useridshort,useridSave,USERMAXLN);
+    strlcpy(extraId,"",USERMAXLN);
+    strlcpy(useridshort,useridSave,USERMAXLN);
   }else{
     /* pick up extraId */
     *markPnt='\0';
-    strncpy(extraId,markPnt+1,USERMAXLN);
-    strncpy(useridshort,useridSave,USERMAXLN);
+    strlcpy(extraId,markPnt+1,USERMAXLN);
+    strlcpy(useridshort,useridSave,USERMAXLN);
   }
 } 
 
@@ -335,10 +335,10 @@ concatinate userid and extraid
 char* concatUserId(char* useridfull, char* userId, char* extraId){
 
   /* set full userid */
-  strncpy(useridfull, userId,USERMAXLN);
+  strlcpy(useridfull, userId,USERMAXLN);
   if(!isNull(extraId)){
-    strncat(useridfull, GetConfValue("UserIdSeparator"), USERMAXLN);
-    strncat(useridfull, extraId, USERMAXLN);
+    strlcat(useridfull, GetConfValue("UserIdSeparator"), USERMAXLN);
+    strlcat(useridfull, extraId, USERMAXLN);
   }
   return useridfull;
 }
index c17c82d..ab53543 100644 (file)
@@ -42,7 +42,7 @@ void decode(char *string);
 /*******************************/
 void getClientAddr(char *clientAddr)
 {
-  strncpy(clientAddr, getenv("REMOTE_ADDR"), ADDRMAXLN);
+  strlcpy(clientAddr, getenv("REMOTE_ADDR"), ADDRMAXLN);
 }
 
 /********************************************/
@@ -87,17 +87,17 @@ int getPostData(char *userid, char *password, char *clientAddr4, int *durationPt
       split(ptr, name, value, next);
       
       if(strstr(name[0], "userid")!=NULL){
-       strncpy(userid, value[0], USERMAXLN);
+       strlcpy(userid, value[0], USERMAXLN);
       }else if(strstr(name[0], "password")!=NULL){
-       strncpy(password, value[0], PASSMAXLN);
+       strlcpy(password, value[0], PASSMAXLN);
       }else if(strstr(name[0],"remote_addr")!=NULL){
-       strncpy(encodeAddr4,value[0],ADDRMAXLN);
+       strlcpy(encodeAddr4,value[0],ADDRMAXLN);
       }else if(strstr(name[0], "language")!=NULL){
-       strncpy(language, value[0], WORDMAXLN);
+       strlcpy(language, value[0], WORDMAXLN);
       }else if(strstr(name[0], "duration")!=NULL){
-       strncpy(durationStr, value[0], WORDMAXLN);
+       strlcpy(durationStr, value[0], WORDMAXLN);
       }else if(strstr(name[0], "redirected_url")!=NULL){
-       strncpy(redirectedUrl, value[0], BUFFMAXLN);
+       strlcpy(redirectedUrl, value[0], BUFFMAXLN);
       }
       ptr=next[0];
     }
@@ -108,7 +108,7 @@ int getPostData(char *userid, char *password, char *clientAddr4, int *durationPt
      &&(queryStrLen=strlen(getenv("QUERY_STRING")))!=0){
 
     /* get html access parameter string */
-    strncpy(queryStr, getenv("QUERY_STRING"), BUFFMAXLN);
+    strlcpy(queryStr, getenv("QUERY_STRING"), BUFFMAXLN);
 
     /* split language and address in content
        [addr=0-0-0&lang=ja&redirectedurl=xxxx] */
@@ -116,11 +116,11 @@ int getPostData(char *userid, char *password, char *clientAddr4, int *durationPt
     while(ptr!=NULL){
       split(ptr, name, value, next);
       if(strstr(name[0], "addr")!=NULL){
-       strncpy(encodeAddr4,value[0],ADDRMAXLN);
+       strlcpy(encodeAddr4,value[0],ADDRMAXLN);
       }else if(strstr(name[0], "lang")!=NULL){
-       strncpy(language, value[0], WORDMAXLN);
+       strlcpy(language, value[0], WORDMAXLN);
       }else if(strstr(name[0], "redirectedurl")!=NULL){
-       strncpy(redirectedUrl, value[0], BUFFMAXLN);
+       strlcpy(redirectedUrl, value[0], BUFFMAXLN);
       }
       ptr=next[0];
     }
@@ -141,7 +141,7 @@ int getPostData(char *userid, char *password, char *clientAddr4, int *durationPt
   decode(redirectedUrl);
 
  /* if not available language, use first lang */
-  strncpy(langList, GetConfValue("HtmlLangs"), BUFFMAXLN);  /* list of available languages */
+  strlcpy(langList, GetConfValue("HtmlLangs"), BUFFMAXLN);  /* list of available languages */
   if(isNull(language) || strstr(langList,language)==NULL){
     sscanf(langList,"%s",language);
   }
@@ -166,10 +166,10 @@ int getPostData(char *userid, char *password, char *clientAddr4, int *durationPt
   }
 
   /* if the decoded IPv4 addr is not same as access IPv4 addr, use later */
-  strncpy(accessAddr, getenv("REMOTE_ADDR"), ADDRMAXLN);
+  strlcpy(accessAddr, getenv("REMOTE_ADDR"), ADDRMAXLN);
   if((strnstr(accessAddr, ".", ADDRMAXLN)!=NULL)   /* access is IPv4 */
      && strncmp(accessAddr, clientAddr4, ADDRMAXLN)!=0){  /* and not same */
-    strncpy(clientAddr4, accessAddr, ADDRMAXLN);
+    strlcpy(clientAddr4, accessAddr, ADDRMAXLN);
   }
 
   /* if no userid, set useid="?" */
@@ -195,13 +195,13 @@ int getUserIdFromEnv(char *userid){
   if(strcmp(GetConfValue("AuthServer/Protocol"), "shibboleth")==0){
     pEnv=getenvEx(GetConfValue("AuthServer/UidAttribute"),TRUE,TRUE);
     if(!isNull(pEnv)){
-      strncpy(userid, pEnv, USERMAXLN);
+      strlcpy(userid, pEnv, USERMAXLN);
 
       /* if idp string can be get from env variable, concatinate it as uid@org */
       pEnv=getenvEx(GetConfValue("AuthServer/OrgAttribute"),TRUE,TRUE);
       if(!isNull(pEnv)){
-       strncat(userid, GetConfValue("UserIdSeparator"), USERMAXLN);
-       strncat(userid, pEnv, USERMAXLN);
+       strlcat(userid, GetConfValue("UserIdSeparator"), USERMAXLN);
+       strlcat(userid, pEnv, USERMAXLN);
       } 
       ret=TRUE;
     }
@@ -210,7 +210,7 @@ int getUserIdFromEnv(char *userid){
     else{
       pEnv=getenvEx(GetConfValue("AuthServer/EppnAttribute"),TRUE,FALSE);
       if(!isNull(pEnv)){
-       strncat(userid, pEnv, USERMAXLN);
+       strlcat(userid, pEnv, USERMAXLN);
        ret=TRUE;
       }
     }
@@ -226,7 +226,7 @@ int getUserIdFromEnv(char *userid){
   /* httpbasic */
   else if(strcmp(GetConfValue("AuthServer/Protocol"), "httpbasic")==0){
     if(!isNull(getenv("REMOTE_USER"))){
-      strncpy(userid,getenv("REMOTE_USER"),USERMAXLN);
+      strlcpy(userid,getenv("REMOTE_USER"),USERMAXLN);
       ret=TRUE;
     }else{
       err_msg("ERR at %s#%d: Cannot get user info from httpbasic",__FILE__,__LINE__);
@@ -287,7 +287,7 @@ int getAuthCookie(char *cookie, char *userid){
 
  /* if exist cookie, copy it to work area */
   if(isNull(getenv("HTTP_COOKIE"))) return FALSE;
-  strncpy(content, getenv("HTTP_COOKIE"), BUFFMAXLN);
+  strlcpy(content, getenv("HTTP_COOKIE"), BUFFMAXLN);
   ptr=content;
 
   /* search 'OpengateAuth' cookie string (terminated by ; or \0) */
@@ -305,9 +305,9 @@ int getAuthCookie(char *cookie, char *userid){
     split(ptr, name, value, next);
 
     if(strstr(name[0], COOKIENAME)!=NULL){
-      strncpy(cookie, value[0], SIDMAXLN);
+      strlcpy(cookie, value[0], SIDMAXLN);
     }else if(strstr(name[0], "Userid")!=NULL){
-      strncpy(userid, value[0], USERMAXLN);
+      strlcpy(userid, value[0], USERMAXLN);
     }
     ptr=next[0];
   }
@@ -356,9 +356,9 @@ void putClientDeny(char *clientAddr4, char *language)
 
   /* protocol is ssl or non-ssl */
   if(strcmp(getenv("SERVER_PORT"),GetServicePortStr("https"))==0){
-    strncpy(protocol, "https",WORDMAXLN);
+    strlcpy(protocol, "https",WORDMAXLN);
   }else{
-    strncpy(protocol, "http",WORDMAXLN);
+    strlcpy(protocol, "http",WORDMAXLN);
   }
 
   /* document path to deny doc */
@@ -406,7 +406,7 @@ void putClientRetry(char *language)
   snprintf(opengateDir, BUFFMAXLN, GetConfValue("OpengateDir"));
  
   /* create external URL string */
-  strncpy(externalUrl, GetConfValue("ExternalUrl"), BUFFMAXLN);
+  strlcpy(externalUrl, GetConfValue("ExternalUrl"), BUFFMAXLN);
 
   /* create authcgi URL string */
   snprintf(authCgiUrl, BUFFMAXLN, "%s%s%s/%s",
@@ -654,7 +654,7 @@ int checkReferer(void)
 {
   char url[BUFFMAXLN]="";
   if(getenv("HTTP_REFERER")!=NULL){
-    strncpy(url,getenv("HTTP_REFERER"),BUFFMAXLN);
+    strlcpy(url,getenv("HTTP_REFERER"),BUFFMAXLN);
     if(strstr(url,GetConfValue("OpengateServerName"))==NULL){
       return FALSE;
     }
index d9aabc6..dd7ba76 100644 (file)
@@ -83,7 +83,7 @@ void scanNdpEntry(struct clientAddr *pClientAddr, char *userid, char *macAddr6,
     /* regist it and open firewall for it */
 
     /* cut out ip-ndp */
-    strncpy(tmpAddr,buf,ADDRMAXLN);
+    strlcpy(tmpAddr,buf,ADDRMAXLN);
 
     /* get first ip-reg in address list */
     tmp1 = pClientAddr;
index 7a57f84..20d8cea 100644 (file)
@@ -243,13 +243,13 @@ int getSessionInfoFromDb(char* cookie, char* userid,
 
   /* get first match item */
   if(sqlite3_step(stmt)==SQLITE_ROW){
-    strncpy(userid, (char*)sqlite3_column_text(stmt, 0), USERMAXLN);
-    strncpy(clientAddr4, (char*)sqlite3_column_text(stmt, 1), USERMAXLN);
-    strncpy(macAddr, (char*)sqlite3_column_text(stmt, 2), USERMAXLN);
+    strlcpy(userid, (char*)sqlite3_column_text(stmt, 0), USERMAXLN);
+    strlcpy(clientAddr4, (char*)sqlite3_column_text(stmt, 1), USERMAXLN);
+    strlcpy(macAddr, (char*)sqlite3_column_text(stmt, 2), USERMAXLN);
     *duration=(int)sqlite3_column_int(stmt, 3);
     *durationEntered=(int)sqlite3_column_int(stmt, 4);
-    strncpy(language, (char*)sqlite3_column_text(stmt, 5), WORDMAXLN);
-    strncpy(closeTime, (char*)sqlite3_column_text(stmt, 6), WORDMAXLN);
+    strlcpy(language, (char*)sqlite3_column_text(stmt, 5), WORDMAXLN);
+    strlcpy(closeTime, (char*)sqlite3_column_text(stmt, 6), WORDMAXLN);
     resultFlag=TRUE;
   }else{
     resultFlag=FALSE;
index 01c4ddf..7744d36 100644 (file)
@@ -86,7 +86,7 @@ int addAlarm(char *name, int timeout, int preceding, Sigfunc *func)
   }
 
   /* set the item info */
-  strncpy(pNew->name, name, WORDMAXLN);
+  strlcpy(pNew->name, name, WORDMAXLN);
   pNew->timeout = timeout;
   pNew->unixtime = time(NULL) + timeout;
   pNew->preceding = preceding;
index d6baf10..97c5c08 100644 (file)
@@ -192,8 +192,8 @@ struct clientAddr *createAddrListItem(char* ipAddr, char *ruleNumber, int ipType
     PutClientMsg("Error: Please contact to the administrator");
     exit(1);
   }
-  strncpy(pNew->ipAddr,ipAddr,ADDRMAXLN);
-  strncpy(pNew->ruleNumber,ruleNumber,WORDMAXLN);
+  strlcpy(pNew->ipAddr,ipAddr,ADDRMAXLN);
+  strlcpy(pNew->ruleNumber,ruleNumber,WORDMAXLN);
   pNew->ipType = ipType;
   pNew->timeIn = time(NULL);
   pNew->activeStatus=TRUE;
index ae43d58..41889d4 100644 (file)
@@ -56,9 +56,9 @@ int openConfFile(void)
   if((xmlRoot = ezxml_parse_file(CONFIGFILE))==NULL){
 
     /* as the syslog is not prepared, error is send to web*/
-    strncpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
-    strncat(buff, CONFIGFILE,BUFFMAXLN);
-    strncat(buff, " is not found. Call the administrator.</H3><BR>",BUFFMAXLN);
+    strlcpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
+    strlcat(buff, CONFIGFILE,BUFFMAXLN);
+    strlcat(buff, " is not found. Call the administrator.</H3><BR>",BUFFMAXLN);
      PutClientMsg(buff);
 
     return -1;
@@ -72,12 +72,12 @@ int openConfFile(void)
 
   if(*errMsg!='\0'){
     /* as the syslog is not prepared, error is send to web*/
-    strncpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
-    strncat(buff, CONFIGFILE,BUFFMAXLN);
-    strncat(buff, " is illegal. Call the administrator.</H3><HR>",BUFFMAXLN);
-    strncat(buff, "XML parser message: ", BUFFMAXLN);
-    strncat(buff, errMsg, BUFFMAXLN);
-    strncat(buff, "<HR>", BUFFMAXLN);
+    strlcpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
+    strlcat(buff, CONFIGFILE,BUFFMAXLN);
+    strlcat(buff, " is illegal. Call the administrator.</H3><HR>",BUFFMAXLN);
+    strlcat(buff, "XML parser message: ", BUFFMAXLN);
+    strlcat(buff, errMsg, BUFFMAXLN);
+    strlcat(buff, "<HR>", BUFFMAXLN);
      PutClientMsg(buff);
 
     return -1;
@@ -86,11 +86,11 @@ int openConfFile(void)
   /* check the config file version */ 
   if(isNull(ezxml_attr(xmlRoot, "ConfigVersion"))||
      (strcmp(CONFIG_VERSION, ezxml_attr(xmlRoot, "ConfigVersion"))!=0)){
-    strncpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
-    strncat(buff, CONFIGFILE, BUFFMAXLN);
-    strncat(buff, " has mismatch version.<br> Please update it with ",BUFFMAXLN);
-    strncat(buff, CONFIGFILE, BUFFMAXLN);
-    strncat(buff, ".sample.",BUFFMAXLN);
+    strlcpy(buff, "<H3>Error: Opengate configuration file ",BUFFMAXLN);
+    strlcat(buff, CONFIGFILE, BUFFMAXLN);
+    strlcat(buff, " has mismatch version.<br> Please update it with ",BUFFMAXLN);
+    strlcat(buff, CONFIGFILE, BUFFMAXLN);
+    strlcat(buff, ".sample.",BUFFMAXLN);
      PutClientMsg(buff);
 
     return -1;
@@ -101,9 +101,9 @@ int openConfFile(void)
      atoi(GetConfValue("Syslog/Facility"))==0){
 
     /* as the syslog is not prepared, error is send to web*/
-    strncpy(buff, "<H3>Error: correct SYSLOG setting(local0-local7) is not found in Opengate configuration file ",BUFFMAXLN);
-    strncat(buff, CONFIGFILE,BUFFMAXLN);
-    strncat(buff, ". Call the administrator.</H3><BR>",BUFFMAXLN);
+    strlcpy(buff, "<H3>Error: correct SYSLOG setting(local0-local7) is not found in Opengate configuration file ",BUFFMAXLN);
+    strlcat(buff, CONFIGFILE,BUFFMAXLN);
+    strlcat(buff, ". Call the administrator.</H3><BR>",BUFFMAXLN);
      PutClientMsg(buff);
 
     return -1;
@@ -257,7 +257,7 @@ char *getConfValue(char *name)
   if(strstr(name,"AuthServer/")==name) return GetConfAuthServer(name);
 
   /* copy name to work area */
-  strncpy(buff,name,BUFFMAXLN);
+  strlcpy(buff,name,BUFFMAXLN);
 
   /* get first token */
   pStr=strtok(buff, SEPARATOR);
@@ -307,7 +307,7 @@ char *getConfValueExtra(char *name)
   if(xmlExtraSet==NULL) return "";
 
   /* extract first token in name */
-  strncpy(buff,name,BUFFMAXLN);
+  strlcpy(buff,name,BUFFMAXLN);
   pStr=strtok(buff, SEPARATOR);  
 
   /* get a first level matched node in extra set */
@@ -340,7 +340,7 @@ char *getConfAuthServer(char *name)
   ezxml_t xml;
 
   /* copy name to work area */
-  strncpy(buff,name,BUFFMAXLN);
+  strlcpy(buff,name,BUFFMAXLN);
 
   /* get first token */
   pStr=strtok(buff, SEPARATOR);
index a6dc2b5..5b7da65 100644 (file)
@@ -67,16 +67,16 @@ int htmlReplace(char* buff,char *beforeStr,char *afterStr)
   
   if(buff==NULL) return 1;
 
-  strncpy(tempBuff, buff, BUFFMAXLN);
-  strncpy(buff,"",BUFFMAXLN);
+  strlcpy(tempBuff, buff, BUFFMAXLN);
+  strlcpy(buff,"",BUFFMAXLN);
   
   for(pBuff = tempBuff;
       (pNext=strSplit(pBuff, beforeStr)) != NULL;
       pBuff = pNext){
-    strncat(buff,pBuff,BUFFMAXLN);
-    strncat(buff,afterStr,BUFFMAXLN);
+    strlcat(buff,pBuff,BUFFMAXLN);
+    strlcat(buff,afterStr,BUFFMAXLN);
   }
-  strncat(buff,pBuff,BUFFMAXLN);
+  strlcat(buff,pBuff,BUFFMAXLN);
   
   return 0;
 }
index 7c9042a..939b430 100644 (file)
@@ -109,7 +109,7 @@ int  main(int argc, char **argv)
   if(!isNull(getenv("QUERY_STRING"))){
 
     /* get html access parameter string (attached at the end of url) */
-    strncpy(paramString, getenv("QUERY_STRING"), BUFFMAXLN);
+    strlcpy(paramString, getenv("QUERY_STRING"), BUFFMAXLN);
   }
 
   /* split language and address in paramString
@@ -131,14 +131,14 @@ int  main(int argc, char **argv)
   if(isNull(pAddr4)){
     clientAddr[0]='\0';
   }else{
-    strncpy(clientAddr, pAddr4, ADDRMAXLN);
+    strlcpy(clientAddr, pAddr4, ADDRMAXLN);
   }
 
   /* get language and check its correctness */
   if(!isNull(pLang) && strstr(GetConfValue("HtmlLangs"), pLang)!=NULL){
 
     /* if corrrect, set it */
-    strncpy(lang, pLang, WORDMAXLN);
+    strlcpy(lang, pLang, WORDMAXLN);
   }else{
 
     /* if not correct, get default language at the top of lang list */
@@ -146,7 +146,7 @@ int  main(int argc, char **argv)
   }
 
   /* copy redirected URL */
-  strncpy(redirectedUrl, pUrl, BUFFMAXLN);
+  strlcpy(redirectedUrl, pUrl, BUFFMAXLN);
 
   /* send out header */
   printf("Content-Type: text/html\r\n\r\n");
@@ -162,14 +162,14 @@ int  main(int argc, char **argv)
      || strcmp(authProtocol, "shibboleth")==0 
      || strcmp(authProtocol, "httpbasic")==0 ){
 
-    strncat(htmlFile, GetConfValue("SkipAuthDoc"), BUFFMAXLN);
+    strlcat(htmlFile, GetConfValue("SkipAuthDoc"), BUFFMAXLN);
 
     /* ssl or non-ssl protocol  */
     if(!isNull(getenv("SERVER_PORT"))
        && strcmp(getenv("SERVER_PORT"),GetServicePortStr("https"))==0) {
-      strncpy(protocol, "https", WORDMAXLN);
+      strlcpy(protocol, "https", WORDMAXLN);
     }else{
-      strncpy(protocol, "http", WORDMAXLN);
+      strlcpy(protocol, "http", WORDMAXLN);
     }
   }
   
@@ -178,9 +178,9 @@ int  main(int argc, char **argv)
     /* ssl or non-ssl file */
     if(!isNull(getenv("SERVER_PORT"))
        && strcmp(getenv("SERVER_PORT"),GetServicePortStr("https"))==0) {
-      strncat(htmlFile, GetConfValue("AuthDocSsl"), BUFFMAXLN);
+      strlcat(htmlFile, GetConfValue("AuthDocSsl"), BUFFMAXLN);
     }else{
-      strncat(htmlFile, GetConfValue("AuthDoc"), BUFFMAXLN);
+      strlcat(htmlFile, GetConfValue("AuthDoc"), BUFFMAXLN);
     }
   }
 
index b122164..0ca85e7 100644 (file)
@@ -99,7 +99,7 @@ int  main(int argc, char **argv)
   if(isNull(getenv("QUERY_STRING"))){
     lang[0]='\0';
   }else{
-    strncpy(lang, getenv("QUERY_STRING"), ADDRMAXLN);
+    strlcpy(lang, getenv("QUERY_STRING"), ADDRMAXLN);
   }
      
   /* if not get, use default lang at the top of lang list */
@@ -116,7 +116,7 @@ int  main(int argc, char **argv)
   if(isNull(getenv("REMOTE_ADDR"))){
     clientAddr[0]='\0';
   }else{
-    strncpy(clientAddr,getenv("REMOTE_ADDR"),ADDRMAXLN);
+    strlcpy(clientAddr,getenv("REMOTE_ADDR"),ADDRMAXLN);
   }
 
   /* encode the address(if IPv6 addr, return 0-0-0) */
index a7dc341..c964adf 100644 (file)
@@ -60,7 +60,7 @@ int  main(int argc, char **argv)
 
   /* open firewall */
   OpenClientGate4(clientAddr,"user1",NULL,NULL);
-  strncpy(ClientAddr.ipAddr,clientAddr,ADDRMAXLN);
+  strlcpy(ClientAddr.ipAddr,clientAddr,ADDRMAXLN);
   ClientAddr.ipType = IPV4;
   ClientAddr.timeIn = time(NULL);
   ClientAddr.next = NULL;
@@ -70,7 +70,7 @@ int  main(int argc, char **argv)
   printf("This program and ipfw command be executed by root user\n\n");
   printf("ENTER ANY charcter to remove the added rule\n\n");
   scanf("%s",dummy);
-  strncpy(ClientAddr.ruleNumber,dummy,WORDMAXLN);
+  strlcpy(ClientAddr.ruleNumber,dummy,WORDMAXLN);
 
   /* close firewall */
   CloseClientGate4(pClientAddr,"user1",NULL);
index a3996eb..a53d34f 100644 (file)
@@ -41,9 +41,9 @@ int  main(int argc, char **argv)
   struct clientAddr *pClientAddr;
 
   pClientAddr = &ClientAddr;
-  strncpy(ClientAddr.ipAddr,"127.0.0.1",ADDRMAXLN);
+  strlcpy(ClientAddr.ipAddr,"127.0.0.1",ADDRMAXLN);
   ClientAddr.next=NULL;
-  strncpy(ClientAddr.ruleNumber,"10000",WORDMAXLN);
+  strlcpy(ClientAddr.ruleNumber,"10000",WORDMAXLN);
   ClientAddr.ipType=IPV4;
   ClientAddr.timeIn=time(NULL);
 
index 81d8d11..616e146 100644 (file)
@@ -210,14 +210,14 @@ FILE *Popenl(int rootPriv, const char *type, const char *path, ...)
   FILE *file;
 
   /* insert command path */
-  strncpy(commandLine, path, BUFFMAXLN);
+  strlcpy(commandLine, path, BUFFMAXLN);
 
   /* insert command arguments */
   va_start(ap, path);
   
   while((pStr=va_arg(ap, char *))!=(char *)0){
     strcat(commandLine, " ");
-    strncat(commandLine, pStr, BUFFMAXLN);
+    strlcat(commandLine, pStr, BUFFMAXLN);
   }
 
   va_end(ap);
@@ -257,14 +257,14 @@ int Systeml(int rootPriv, const char *path, ...)
   int ret;
 
   /* insert command path */
-  strncpy(commandLine, path, BUFFMAXLN);
+  strlcpy(commandLine, path, BUFFMAXLN);
 
   /* insert command arguments */
   va_start(ap, path);
   
   while((pStr=va_arg(ap, char *))!=(char *)0){
     strcat(commandLine, " ");
-    strncat(commandLine, pStr, BUFFMAXLN);
+    strlcat(commandLine, pStr, BUFFMAXLN);
   }
 
   va_end(ap);
@@ -385,7 +385,7 @@ char* getenvEx(char* env, int pre, int post){
   int found=FALSE;
 
   /* copy string not to destroy it */
-  strncpy(work, env, BUFFMAXLN);
+  strlcpy(work, env, BUFFMAXLN);
 
   /* repeat for variables */
   thisVar=nextVar=work;
index f89636b..a1e80e7 100644 (file)
@@ -496,7 +496,7 @@ void getPeerAddr(int sockfd, char *peerAddr)
   if(Getpeername(sockfd, cliaddr, &len)<0) return; /* if error, return */
     
   pAddr=Sock_ntop_host(cliaddr, len);
-  if(pAddr!=NULL) strncpy(peerAddr, pAddr, ADDRMAXLN);
+  if(pAddr!=NULL) strlcpy(peerAddr, pAddr, ADDRMAXLN);
   
   free(cliaddr);
   
@@ -603,7 +603,7 @@ void waitHttpClose(struct clientAddr *pClientAddr, char *userid, char *userPrope
        }
 
        /* save hello request string including keys */    
-       strncpy(previousHello, buff, BUFFMAXLN);
+       strlcpy(previousHello, buff, BUFFMAXLN);
 
        /* if received key is correct, save time */
        if(IsRightKey(buff+strlen("GET /hello-"), sessionId)){
@@ -732,7 +732,7 @@ int isRightKey(char *arg, char *sessionId)
   /* initial value of savedKey is md5(md5(sessionId)+sessionId) */
   if(isNull(savedKey)){
     md5hex(tempbuff, 33, sessionId);
-    strncat(tempbuff, sessionId, BUFFMAXLN);
+    strlcat(tempbuff, sessionId, BUFFMAXLN);
     md5hex(savedKey, 33, tempbuff);
   }
 
@@ -744,14 +744,14 @@ int isRightKey(char *arg, char *sessionId)
   *(pNextKey+32)='\0';
 
   /* make string [nowKey+sessionId] */
-  strncpy(tempbuff, pNowKey, BUFFMAXLN);
-  strncat(tempbuff, sessionId, BUFFMAXLN);
+  strlcpy(tempbuff, pNowKey, BUFFMAXLN);
+  strlcat(tempbuff, sessionId, BUFFMAXLN);
 
   /* compare savedKey and md5(nowKey+sessionId) */
   if(strcmp(savedKey, md5hex(md5work, 33, tempbuff))==0){
 
     /* save nextKey for next check */
-    strncpy(savedKey, pNextKey, 33);
+    strlcpy(savedKey, pNextKey, 33);
     return TRUE;
   }
   else{