From 5ffe4f39058591043293ed694024c9b2d2d35657 Mon Sep 17 00:00:00 2001 From: zolliker Date: Thu, 15 Apr 2010 09:40:27 +0000 Subject: [PATCH] - fixed some strlcpy bugs --- sicshipadaba.c | 1 + sinfox.c | 2 +- stringdict.c | 15 --------------- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/sicshipadaba.c b/sicshipadaba.c index 4ca4953e..21532af7 100644 --- a/sicshipadaba.c +++ b/sicshipadaba.c @@ -1064,6 +1064,7 @@ static hdbCallbackReturn MemGenSetCallback(pHdb node, void *userData, memcpy(userData, &mm->v->v.doubleValue, sizeof(double)); break; case HIPTEXT: + /* the use of strlcpy is probably buggy here (M.Z. 15.4.2010) */ strlcpy((char *) userData, (const char *) mm->v->v.text, node->value.arrayLength); break; diff --git a/sinfox.c b/sinfox.c index 63736706..8b7874ad 100644 --- a/sinfox.c +++ b/sinfox.c @@ -378,7 +378,7 @@ static int SinfoxReadKey(pSinfox pSin, SicsInterp * pSics, continue; iLen = pPos - pBuf; - strlcpy(pName, pBuf, iLen); + strncpy(pName, pBuf, iLen); /* strlcpy is wrong here */ pName[iLen] = '\0'; strcpy(pValue, (pPos + 1)); RemoveWhiteSpace(pName); diff --git a/stringdict.c b/stringdict.c index 836c0d79..eaa090f8 100644 --- a/stringdict.c +++ b/stringdict.c @@ -170,11 +170,6 @@ int StringDictGet(pStringDict self, char *name, char *pResult, int iLen) return strlen(sVal.value) + 1; /* for \0 */ } else { strlcpy(pResult, sVal.value, iLen); - /* strncpy is not guaranteed to be '\0' terminated */ - if (iLen > 0 && pResult[iLen - 1] != '\0') { - /* overflow */ - pResult[iLen - 1] = '\0'; - } return 1; } } @@ -261,11 +256,6 @@ const char *StringDictGetNext(pStringDict self, char *pValue, int iValLen) } else { LLDnodeDataTo(self->iList, &sVal); strlcpy(pValue, sVal.value, iValLen); - /* strncpy is not guaranteed to be '\0' terminated */ - if (iValLen > 0 && pValue[iValLen-1] != '\0') { - /* overflow */ - pValue[iValLen-1] = '\0'; - } return sVal.name; } @@ -278,11 +268,6 @@ const char *StringDictGetNext(pStringDict self, char *pValue, int iValLen) self->iTraverse = 1; LLDnodeDataTo(self->iList, &sVal); strlcpy(pValue, sVal.value, iValLen); - /* strncpy is not guaranteed to be '\0' terminated */ - if (iValLen > 0 && pValue[iValLen-1] != '\0') { - /* overflow */ - pValue[iValLen-1] = '\0'; - } return sVal.name; } }