#1460 Check STAF_INSTANCE_NAME validity when STAFProc starts

All
closed-fixed
STAFProc (180)
5
2012-07-31
2012-05-24
No

The STAF User's Guide does not define what is a valid value for the STAF_INSTANCE_NAME environment variable. However, we get various errors starting STAFProc if the STAF_INSTANCE_NAME value is set to one or more spaces, or if it ends in one or more spaces, or contains characters that cannot be used in a file name. STAFProc should add some checking on the value of the STAF_INSTANCE_NAME and not start STAFProc if the STAF_INSTANCE_NAME is set to an invalid value.

For example, on Windows:

1) If set STAF_INSTANCE_NAME to one or more blanks, STAFProc fails to start with the following error that doesn't mention anything about an invalid STAF_INSTANCE_NAME:

C:\>set STAF_INSTANCE_NAME=
C:\>STAFProc

Machine : client.austin.ibm.com
Machine nickname : sharon
Startup time : 20120524-15:30:42
Error creating DATADIR directory: C:\STAF\data\

C:\>

2) If set STAF_INSTANCE_NAME to a value that ends in one or more spaces, e.g. "My STAF ", STAFProc starts up but with the following errors that don't mention anything about an invalid STAF_INSTANCE_NAME and can encounter problems later on because it couldn't create the tmp or user directories:
C:\>set STAF_INSTANCE_NAME=My STAF

C:\>STAFProc

Machine : client.austin.ibm.com
Machine nickname : sharon
Startup time : 20120524-15:35:45
Error creating temp directory: C:\dev\sf\rel\win32\staf\retail\data\My STAF \tmp
Error creating user directory: C:\dev\sf\rel\win32\staf\retail\data\My STAF \user

LifeCycle Service Initialization Error:
Cannot create directory C:\dev\sf\rel\win32\staf\retail\data\My STAF \service\lifecycle
STAFLogService.cpp: STAFServiceInit: Invalid Log Directory: C:\dev\sf\rel\win32\ staf\retail\data\My STAF \service\log
Error initializing service, LOG, RC: 27, Result: Error initializing service, STAFLog,
Result: STAFLogService.cpp: STAFServiceInit: Invalid Log Directory: C:\STAF\ data\My STAF \service\log

STAFProc version 3.4.9 initialized

3) If set STAF_INSTANCE_NAME to a value that contains one or more characters (such as a colon) that cannot be used in a file name, e.g. My:STAF, STAFProc fails to start with the following error that doesn't mention anything about an invalid STAF_INSTANCE_NAME:

C:\>set STAF_INSTANCE_NAME=My:STAF

C:\>STAFProc c:\staf\bin\bare.cfg

Machine : client.austin.ibm.com
Machine nickname : sharon
Startup time : 20120524-15:42:05
Error creating DATADIR directory: C:\dev\sf\rel\win32\staf\retail\data\My:STAF

C:\>

Also, probably shouldn't allow a file separator (/ or \) to be specified either.

Discussion

  • Sharon Lucas

    Sharon Lucas - 2012-07-30
    • assigned_to: nobody --> slucas
     
  • Sharon Lucas

    Sharon Lucas - 2012-07-30

    Here's a cvs diff of the fix:

    Index: stafproc/STAFProc.cpp

    RCS file: /cvsroot/staf/src/staf/stafproc/STAFProc.cpp,v
    retrieving revision 1.249
    diff -r1.249 STAFProc.cpp
    120a121,122
    > unsigned int verifySTAFInstanceName(const STAFString stafInstanceName,
    > STAFString &errorBuffer);
    368a371,378
    > STAFString errorBuffer = "";
    >
    > if (verifySTAFInstanceName(gSTAFInstanceName, errorBuffer) != 0)
    > {
    > cout << "Invalid value for STAF_INSTANCE_NAME ("
    > << gSTAFInstanceName << ")" << endl << errorBuffer << endl;
    > return 1;
    > }
    4433a4444,4490
    > /* verifySTAFInstanceName - This method verifies that the specified STAF */
    > /* instance name is valid. This check is performed before the STAF */
    > /* instance name is used (e.g. as part of a directory name, etc). */
    > /* */
    > /* Accepts: (In) The STAF instance name */
    > /* (Out) An error message if an error occurs */
    > /* */
    > /* Returns: 0 if the STAF instance name is valid. */
    > /* 1 if the STAF instance name is invalid. A STAF instance name is */
    > /* invalid if it contains any of the following special characters */
    > /* (e.g .which cannot be used as a directory name): */
    > /* ~!#$%^&*+={}[]|;':"?/<>\/ */
    > /* or if it contains any whitespace at the beginning or end */
    > /* or if it only contains whitespace. */
    > /******************************************************************************/
    > unsigned int verifySTAFInstanceName(const STAFString stafInstanceName,
    > STAFString &errorBuffer)
    > {
    > if (stafInstanceName.findFirstOf("~!#$%^&*+={}[]|;':\"?/<>\\/") !=
    > STAFString::kNPos)
    > {
    > errorBuffer = "It cannot contain any of the following characters: "
    > "~!#$%^&*+={}[]|;':\"?/<>\\/";
    > return kSTAFInvalidValue;
    > }
    > else
    > {
    > STAFString strippedInstanceName = stafInstanceName;
    > strippedInstanceName = strippedInstanceName.strip();
    >
    > if (strippedInstanceName.length() == 0)
    > {
    > errorBuffer = "It cannot be empty or just spaces";
    > return kSTAFInvalidValue;
    > }
    > else if (!strippedInstanceName.strip().isEqualTo(stafInstanceName))
    > {
    > errorBuffer = "It cannot contain any leading or trailing "
    > "whitespace.";
    > return kSTAFInvalidValue;
    > }
    > }
    >
    > return kSTAFOk;
    > }
    >
    > /******************************************************************************/

     
  • Sharon Lucas

    Sharon Lucas - 2012-07-31
    • status: open --> closed-fixed
     
  • Sharon Lucas

    Sharon Lucas - 2012-07-31

    This will be in the next STAF release , 3,4,11, planned for the end of September.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks