char arrays are now always 0 terminated when fetching strings with $ suffix
This commit is contained in:
70
fix-907761.patch
Normal file
70
fix-907761.patch
Normal file
@@ -0,0 +1,70 @@
|
||||
=== modified file 'src/db/dbAccess.c'
|
||||
--- src/db/dbAccess.c 2010-10-05 19:27:37 +0000
|
||||
+++ src/db/dbAccess.c 2012-01-06 00:11:42 +0000
|
||||
@@ -969,7 +969,7 @@
|
||||
|
||||
case DBR_CHAR:
|
||||
case DBR_UCHAR:
|
||||
- if (nRequest && *nRequest > 1) {
|
||||
+ if (nRequest && *nRequest > 0) {
|
||||
maxlen = *nRequest - 1;
|
||||
break;
|
||||
}
|
||||
@@ -984,8 +984,8 @@
|
||||
if (!status) status = dbFindField(&dbEntry, pfldDes->name);
|
||||
if (!status) {
|
||||
rtnString = dbGetString(&dbEntry);
|
||||
- strncpy(pbuf, rtnString, maxlen - 1);
|
||||
- pbuf[maxlen - 1] = 0;
|
||||
+ strncpy(pbuf, rtnString, maxlen);
|
||||
+ pbuf[maxlen] = 0;
|
||||
}
|
||||
dbFinishEntry(&dbEntry);
|
||||
} else {
|
||||
@@ -1028,7 +1028,7 @@
|
||||
|
||||
case DBR_CHAR:
|
||||
case DBR_UCHAR:
|
||||
- if (nRequest && *nRequest > 1) {
|
||||
+ if (nRequest && *nRequest > 0) {
|
||||
maxlen = *nRequest - 1;
|
||||
break;
|
||||
}
|
||||
@@ -1037,8 +1037,8 @@
|
||||
return S_db_badDbrtype;
|
||||
}
|
||||
|
||||
- strncpy(pbuf, (char *)paddr->pfield, maxlen - 1);
|
||||
- pbuf[maxlen - 1] = 0;
|
||||
+ strncpy(pbuf, (char *)paddr->pfield, maxlen);
|
||||
+ pbuf[maxlen] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
=== modified file 'src/db/dbConvert.c'
|
||||
--- src/db/dbConvert.c 2009-04-23 18:49:40 +0000
|
||||
+++ src/db/dbConvert.c 2012-01-06 00:13:33 +0000
|
||||
@@ -416,6 +416,10 @@
|
||||
char *pbuffer = (char *)pto;
|
||||
char *psrc=(char *)(paddr->pfield);
|
||||
|
||||
+ if (paddr->pfldDes->field_type == DBF_STRING) {
|
||||
+ pbuffer[--nRequest] = 0;
|
||||
+ if (nRequest == 0) return(0);
|
||||
+ }
|
||||
if(nRequest==1 && offset==0) {
|
||||
*pbuffer = *psrc;
|
||||
return(0);
|
||||
@@ -436,6 +440,10 @@
|
||||
unsigned char *pbuffer = (unsigned char *)pto;
|
||||
char *psrc=(char *)(paddr->pfield);
|
||||
|
||||
+ if (paddr->pfldDes->field_type == DBF_STRING) {
|
||||
+ pbuffer[--nRequest] = 0;
|
||||
+ if (nRequest == 0) return(0);
|
||||
+ }
|
||||
if(nRequest==1 && offset==0) {
|
||||
*pbuffer = *psrc;
|
||||
return(0);
|
||||
|
||||
@@ -964,14 +964,13 @@ long epicsShareAPI dbGetField(DBADDR *paddr,short dbrType,
|
||||
switch (dbrType) {
|
||||
case DBR_STRING:
|
||||
maxlen = MAX_STRING_SIZE - 1;
|
||||
pbuf[maxlen] = 0;
|
||||
if (nRequest && *nRequest > 1) *nRequest = 1;
|
||||
break;
|
||||
|
||||
case DBR_CHAR:
|
||||
case DBR_UCHAR:
|
||||
if (nRequest && *nRequest > 0) {
|
||||
maxlen = *nRequest;
|
||||
maxlen = *nRequest - 1;
|
||||
break;
|
||||
}
|
||||
/* else fall through ... */
|
||||
@@ -986,6 +985,7 @@ long epicsShareAPI dbGetField(DBADDR *paddr,short dbrType,
|
||||
if (!status) {
|
||||
rtnString = dbGetString(&dbEntry);
|
||||
strncpy(pbuf, rtnString, maxlen);
|
||||
pbuf[maxlen] = 0;
|
||||
}
|
||||
dbFinishEntry(&dbEntry);
|
||||
} else {
|
||||
@@ -1023,14 +1023,13 @@ long epicsShareAPI dbGet(DBADDR *paddr, short dbrType,
|
||||
switch (dbrType) {
|
||||
case DBR_STRING:
|
||||
maxlen = MAX_STRING_SIZE - 1;
|
||||
pbuf[maxlen] = 0;
|
||||
if (nRequest && *nRequest > 1) *nRequest = 1;
|
||||
break;
|
||||
|
||||
case DBR_CHAR:
|
||||
case DBR_UCHAR:
|
||||
if (nRequest && *nRequest > 0) {
|
||||
maxlen = *nRequest;
|
||||
maxlen = *nRequest - 1;
|
||||
break;
|
||||
}
|
||||
/* else fall through ... */
|
||||
@@ -1039,6 +1038,7 @@ long epicsShareAPI dbGet(DBADDR *paddr, short dbrType,
|
||||
}
|
||||
|
||||
strncpy(pbuf, (char *)paddr->pfield, maxlen);
|
||||
pbuf[maxlen] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -416,6 +416,10 @@ static long getCharChar(
|
||||
char *pbuffer = (char *)pto;
|
||||
char *psrc=(char *)(paddr->pfield);
|
||||
|
||||
if (paddr->pfldDes->field_type == DBF_STRING) {
|
||||
pbuffer[--nRequest] = 0;
|
||||
if (nRequest == 0) return(0);
|
||||
}
|
||||
if(nRequest==1 && offset==0) {
|
||||
*pbuffer = *psrc;
|
||||
return(0);
|
||||
@@ -436,6 +440,10 @@ static long getCharUchar(
|
||||
unsigned char *pbuffer = (unsigned char *)pto;
|
||||
char *psrc=(char *)(paddr->pfield);
|
||||
|
||||
if (paddr->pfldDes->field_type == DBF_STRING) {
|
||||
pbuffer[--nRequest] = 0;
|
||||
if (nRequest == 0) return(0);
|
||||
}
|
||||
if(nRequest==1 && offset==0) {
|
||||
*pbuffer = *psrc;
|
||||
return(0);
|
||||
|
||||
Reference in New Issue
Block a user