Comment 3 for bug 1597809

Revision history for this message
Andrew Johnson (anj) wrote :

Unless this is an alias dbRecordNode::recordname should be a pointer to dbCommon::name (we only free that storage when DBRN_FLAGS_ISALIAS is set). The reason changing the NAME field causes subsequent PV lookups to fail is that the record is now in the wrong gpHash bucket.

We do have to allow writes to SPC_NOMOD fields when loading the database, as Michael pointed out fields like NEML and FTVL are design fields that are SPC_NOMOD and we have to be able to set them during DB file parsing. The Wiki is out of date, fixes welcome (I can create an account for anyone who doesn't have one).

I would disallow writing to NAME in dbRecordField() in dbLexRoutines.c but strcmp() isn't the quickest way to identify the situation; NAME always has a field index of zero, so here's my fix to 3.14 which should merge up cleanly:

diff --git a/src/dbStatic/dbLexRoutines.c b/src/dbStatic/dbLexRoutines.c
index db95cc6..f9c2f8e 100644
--- a/src/dbStatic/dbLexRoutines.c
+++ b/src/dbStatic/dbLexRoutines.c
@@ -974,6 +974,12 @@ static void dbRecordField(char *name,char *value)
        yyerror(NULL);
        return;
     }
+ if (pdbentry->indfield == 0) {
+ epicsPrintf("Can't set \"NAME\" field of record \"%s\"\n",
+ dbGetRecordName(pdbentry));
+ yyerror(NULL);
+ return;
+ }
     dbTranslateEscape(value, value); /* yuck: in-place, but safe */
     status = dbPutString(pdbentry,value);
     if(status) {