osaf/libs/agents/saf/lga/lga_api.c | 10 ++-
osaf/services/saf/logsv/lgs/lgs_evt.c | 9 ++
tests/logsv/tet_LogOiOps.c | 23 +++++++
tests/logsv/tet_saLogStreamOpen_2.c | 103 ++++++++++++++++++++++++++++++++++
4 files changed, 144 insertions(+), 1 deletions(-)
Log agent and logsv do not validate this input when openning stream using LOG
API.
Fix this defect by adding validation in the log agent as well as logsv.
diff --git a/osaf/libs/agents/saf/lga/lga_api.c
b/osaf/libs/agents/saf/lga/lga_api.c
--- a/osaf/libs/agents/saf/lga/lga_api.c
+++ b/osaf/libs/agents/saf/lga/lga_api.c
@@ -536,7 +536,15 @@ static SaAisErrorT validate_open_params(
if(logFileCreateAttributes->maxLogRecordSize >
logFileCreateAttributes->maxLogFileSize){
TRACE("maxLogRecordSize is greater than the
maxLogFileSize");
return SA_AIS_ERR_INVALID_PARAM;
- }
+ }
+
+ /* Validate maxFilesRotated just in case of
SA_LOG_FILE_FULL_ACTION_ROTATE type */
+ if ((logFileCreateAttributes->logFileFullAction ==
SA_LOG_FILE_FULL_ACTION_ROTATE) &&
+ ((logFileCreateAttributes->maxFilesRotated < 1)
||
+ (logFileCreateAttributes->maxFilesRotated >
127))) {
+ TRACE("Invalid maxFilesRotated. Valid range =
[1-127]");
+ return SA_AIS_ERR_INVALID_PARAM;
+ }
}
*header_type = (uint32_t)SA_LOG_GENERIC_HEADER;
diff --git a/osaf/services/saf/logsv/lgs/lgs_evt.c
b/osaf/services/saf/logsv/lgs/lgs_evt.c
--- a/osaf/services/saf/logsv/lgs/lgs_evt.c
+++ b/osaf/services/saf/logsv/lgs/lgs_evt.c
@@ -797,6 +797,15 @@ static SaAisErrorT create_new_app_stream
goto done;
}
+ /* Validate maxFilesRotated just in case of
SA_LOG_FILE_FULL_ACTION_ROTATE type */
+ if ((open_sync_param->logFileFullAction ==
SA_LOG_FILE_FULL_ACTION_ROTATE) &&
+ ((open_sync_param->maxFilesRotated < 1) ||
+ (open_sync_param->maxFilesRotated > 127))) {
+ TRACE("Invalid maxFilesRotated. Valid Range = [1-127]");
+ rc = SA_AIS_ERR_INVALID_PARAM;
+ goto done;
+ }
+
if (open_sync_param->logFileFmt == NULL) {
TRACE("logFileFmt is NULL, use default one");
const char* logFileFormat = (char *)
lgs_cfg_get(LGS_IMM_LOG_STREAM_FILE_FORMAT);
diff --git a/tests/logsv/tet_LogOiOps.c b/tests/logsv/tet_LogOiOps.c
--- a/tests/logsv/tet_LogOiOps.c
+++ b/tests/logsv/tet_LogOiOps.c
@@ -3108,6 +3108,27 @@ done:
rc = system(command);
}
+/**
+ * Add test case for ticket #1399:
+ * logsv gets stuck in while loop when setting maxFilesRotated=0
+ *
+ * This test case verifies logsv returns error if
+ * setting 0 to saLogStreamMaxFilesRotated attribute.
+ */
+void verMaxFilesRotated(void)
+{
+ int rc;
+ char command[256];
+
+ /* Expect getting exist code = 1 as saLogStreamMaxFilesRotated=0 */
+ strcpy(command, "immcfg -c SaLogStreamConfig
safLgStrCfg=verMaxFilesRotated,safApp=safLogService "
+ "-a saLogStreamFileName=str6file -a saLogStreamPathName=. -a
saLogStreamMaxFilesRotated=0 "
+ "2> /dev/null");
+ rc = system(command);
+ rc_validate(WEXITSTATUS(rc), 1);
+}
+
+
__attribute__ ((constructor)) static void saOiOperations_constructor(void)
{
/* Stream objects */
@@ -3220,6 +3241,8 @@ done:
test_case_add(6, saLogOi_76, "Create: saLogStreamMaxFilesRotated < 128,
Ok");
test_case_add(6, saLogOi_77, "Create: saLogStreamMaxFilesRotated > 128,
ERR");
test_case_add(6, saLogOi_78, "Create: saLogStreamMaxFilesRotated ==
128, ERR");
+ test_case_add(6, verMaxFilesRotated, "Create:
saLogStreamMaxFilesRotated = 0, ERR");
+
/* Tests for modify */
test_case_add(6, saLogOi_100, "Modify: saLogStreamSeverityFilter <
0x7f, Ok");
test_case_add(6, saLogOi_101, "Modify: saLogStreamSeverityFilter >=
0x7f, ERR");
diff --git a/tests/logsv/tet_saLogStreamOpen_2.c
b/tests/logsv/tet_saLogStreamOpen_2.c
--- a/tests/logsv/tet_saLogStreamOpen_2.c
+++ b/tests/logsv/tet_saLogStreamOpen_2.c
@@ -328,6 +328,107 @@ void saLogStreamOpen_2_23(void)
test_validate(rc_17, SA_AIS_ERR_INVALID_PARAM);
}
+/**
+ * Added test cases to verify ticket #1399:
+ * logsv gets stuck in while loop if setting maxFilesRotated = 0.
+ *
+ * This test case verifies logsv returns error if
+ * setting 0 to saLogStreamMaxFilesRotated attribute.
+ */
+void saLogStreamOpen_2_46(void)
+{
+ SaAisErrorT rc = SA_AIS_OK;
+ SaNameT logStreamName = {.length = 0 };
+
+ strcpy((char *)logStreamName.value, SA_LOG_STREAM_APPLICATION1);
+ logStreamName.length = strlen((char *)logStreamName.value);
+
+ SaLogFileCreateAttributesT_2 appLogFileCreateAttributes;
+
+ /* App stream information */
+ appLogFileCreateAttributes.logFilePathName = "appstream";
+ appLogFileCreateAttributes.logFileName = "appstream";
+ appLogFileCreateAttributes.maxLogFileSize = DEFAULT_APP_LOG_FILE_SIZE;
+ appLogFileCreateAttributes.maxLogRecordSize = DEFAULT_APP_LOG_REC_SIZE;
+ appLogFileCreateAttributes.haProperty = SA_TRUE;
+ appLogFileCreateAttributes.logFileFullAction =
SA_LOG_FILE_FULL_ACTION_ROTATE;
+ appLogFileCreateAttributes.maxFilesRotated = 0;
+ appLogFileCreateAttributes.logFileFmt = NULL;
+
+ rc = saLogInitialize(&logHandle, &logCallbacks, &logVersion);
+ if (rc != SA_AIS_OK) {
+ fprintf(stderr, "Failed at saLogInitialize: %d\n ", (int)rc);
+ test_validate(rc, SA_AIS_OK);
+ return;
+ }
+
+ rc = saLogSelectionObjectGet(logHandle, &selectionObject);
+ if (rc != SA_AIS_OK) {
+ fprintf(stderr, "Failed at saLogSelectionObjectGet: %d \n ", (int)rc);
+ test_validate(rc, SA_AIS_OK);
+ goto done;
+ }
+
+ rc = saLogStreamOpen_2(logHandle, &logStreamName,
&appLogFileCreateAttributes,
+ SA_LOG_STREAM_CREATE, SA_TIME_ONE_SECOND,
&logStreamHandle);
+ test_validate(rc, SA_AIS_ERR_INVALID_PARAM);
+
+done:
+ rc = saLogFinalize(logHandle);
+ if (rc != SA_AIS_OK) {
+ fprintf(stderr, "Failed to call salogFinalize: %d\n", (int) rc);
+ }
+}
+
+/**
+ * Verify that setting saLogStreamMaxFilesRotated > 127 is not allowed.
+ * Valid range is in [1 - 127]
+ */
+void saLogStreamOpen_2_47(void)
+{
+ SaAisErrorT rc = SA_AIS_OK;
+ SaNameT logStreamName = {.length = 0 };
+
+ strcpy((char *)logStreamName.value, SA_LOG_STREAM_APPLICATION1);
+ logStreamName.length = strlen((char *)logStreamName.value);
+
+ SaLogFileCreateAttributesT_2 appLogFileCreateAttributes;
+
+ /* App stream information */
+ appLogFileCreateAttributes.logFilePathName = "appstream";
+ appLogFileCreateAttributes.logFileName = "appstream";
+ appLogFileCreateAttributes.maxLogFileSize = DEFAULT_APP_LOG_FILE_SIZE;
+ appLogFileCreateAttributes.maxLogRecordSize = DEFAULT_APP_LOG_REC_SIZE;
+ appLogFileCreateAttributes.haProperty = SA_TRUE;
+ appLogFileCreateAttributes.logFileFullAction =
SA_LOG_FILE_FULL_ACTION_ROTATE;
+ appLogFileCreateAttributes.maxFilesRotated = 128;
+ appLogFileCreateAttributes.logFileFmt = NULL;
+
+ rc = saLogInitialize(&logHandle, &logCallbacks, &logVersion);
+ if (rc != SA_AIS_OK) {
+ fprintf(stderr, "Failed at saLogInitialize: %d\n ", (int)rc);
+ test_validate(rc, SA_AIS_OK);
+ return;
+ }
+
+ rc = saLogSelectionObjectGet(logHandle, &selectionObject);
+ if (rc != SA_AIS_OK) {
+ fprintf(stderr, "Failed at saLogSelectionObjectGet: %d \n ", (int)rc);
+ test_validate(rc, SA_AIS_OK);
+ goto done;
+ }
+
+ rc = saLogStreamOpen_2(logHandle, &logStreamName,
&appLogFileCreateAttributes,
+ SA_LOG_STREAM_CREATE, SA_TIME_ONE_SECOND,
&logStreamHandle);
+ test_validate(rc, SA_AIS_ERR_INVALID_PARAM);
+
+done:
+ rc = saLogFinalize(logHandle);
+ if (rc != SA_AIS_OK) {
+ fprintf(stderr, "Failed to call salogFinalize: %d\n", (int) rc);
+ }
+}
+
extern void saLogStreamOpenAsync_2_01(void);
extern void saLogStreamOpenCallbackT_01(void);
extern void saLogWriteLog_01(void);
@@ -402,5 +503,7 @@ extern void saLogStreamClose_01(void);
test_case_add(2, saLogWriteLogCallbackT_02, "saLogWriteLogCallbackT()
SA_DISPATCH_ALL");
test_case_add(2, saLogFilterSetCallbackT_01, "saLogFilterSetCallbackT OK");
test_case_add(2, saLogStreamClose_01, "saLogStreamClose OK");
+ test_case_add(2, saLogStreamOpen_2_46, "saLogStreamOpen_2 with
maxFilesRotated = 0, ERR");
+ test_case_add(2, saLogStreamOpen_2_47, "saLogStreamOpen_2 with
maxFilesRotated = 128, ERR");
}
------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel