Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v2.x/staging' into v3.x/staging
Browse files Browse the repository at this point in the history
Signed-off-by: 1000TurquoisePogs <[email protected]>
  • Loading branch information
1000TurquoisePogs committed Sep 18, 2024
2 parents 342d076 + cf8c51d commit 16f1749
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 23 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Zowe Common C Changelog

## `3.1.0`
- Feature: added javascript `zos.getStatvfs(path)` function to obtain file system information (#482).

## `3.0.0`
- Feature: added javascript `zos.getStatvfs(path)` function to obtain file system information (#482).
- Add support for LE 64-bit in isgenq.c (#422).
- Bugfix: IARV64 results must be checked for 0x7FFFF000 (#474)

## `2.18.1`
- Bugfix: IARV64 results must be checked for 0x7FFFF000 (#474)
- Bugfix: SLH should not ABEND when MEMLIMIT is reached (additional NULL check)
- Bugfix: support cross-memory server parameters longer than 128 characters
(zowe/zss#684)

## `2.18.0`
- Minor `components.zss.logLevels._zss.httpserver=5` debug messages enhancement (#471)

## `2.17.0`
- Fixed `xplatform.loadFileUTF8` when trying to open nonexistent file (#454)
- Bugfix: fix an incorrect check in the recovery router code which might lead to
Expand Down
193 changes: 176 additions & 17 deletions c/crossmemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "utils.h"
#include "zvt.h"

#define CMS_STATIC_ASSERT($expr) typedef char p[($expr) ? 1 : -1]

#define CROSS_MEMORY_SERVER_MIN_NAME_LENGTH 4
#define CROSS_MEMORY_SERVER_MAX_NAME_LENGTH 16

Expand Down Expand Up @@ -598,12 +600,32 @@ typedef struct CrossMemoryServerConfigServiceParm_tag {
char eyecatcher[8];
#define CMS_CONFIG_SERVICE_PARM_EYECATCHER "RSCMSCSY"
char nameNullTerm[CMS_CONFIG_PARM_MAX_NAME_LENGTH + 1];
char padding[7];
CrossMemoryServerConfigParm result;
uint8_t version;
#define CMS_CONFIG_SERVICE_PARM_VERSION_0 0
#define CMS_CONFIG_SERVICE_PARM_VERSION_2 2
#define CMS_CONFIG_SERVICE_PARM_SIZE_V0 227
#define CMS_CONFIG_SERVICE_PARM_SIZE_V2 227
#define CMS_CONFIG_SERVICE_PARM_VERSION CMS_CONFIG_SERVICE_PARM_VERSION_2
char padding[6];
union {
CrossMemoryServerConfigParm result;
struct { // only for versions >= 2
int32_t nameLength;
int32_t valueBufferLength;
PAD_LONG(0, const char *name);
PAD_LONG(1, void *valueBuffer);
CrossMemoryServerConfigParmExt result;
} ext;
};
} CrossMemoryServerConfigServiceParm;

ZOWE_PRAGMA_PACK_RESET

CMS_STATIC_ASSERT(CMS_CONFIG_SERVICE_PARM_SIZE_V0 ==
sizeof(CrossMemoryServerConfigServiceParm));
CMS_STATIC_ASSERT(CMS_CONFIG_SERVICE_PARM_SIZE_V2 ==
sizeof(CrossMemoryServerConfigServiceParm));

static void initLogMessagePrefix(LogMessagePrefix *prefix) {
LogTimestamp currentTime;
getCurrentLogTimestamp(&currentTime);
Expand Down Expand Up @@ -984,7 +1006,7 @@ int cmsAddConfigParm(CrossMemoryServer *server,
ShortLivedHeap *slh = server->slh;

size_t keyLength = strlen(name);
if (keyLength > CMS_CONFIG_PARM_MAX_NAME_LENGTH) {
if (keyLength > CMS_CONFIG_PARM_EXT_MAX_NAME_LENGTH) {
return RC_CMS_CONFIG_PARM_NAME_TOO_LONG;
}

Expand All @@ -995,28 +1017,33 @@ int cmsAddConfigParm(CrossMemoryServer *server,

strcpy(keyNullTerm, name);

CrossMemoryServerConfigParm *parm =
(CrossMemoryServerConfigParm *)SLHAlloc(
CrossMemoryServerConfigParmExt *parm =
(CrossMemoryServerConfigParmExt *)SLHAlloc(
slh,
sizeof(CrossMemoryServerConfigParm)
sizeof(CrossMemoryServerConfigParmExt)
);
if (parm == NULL) {
return RC_CMS_SLH_ALLOC_FAILED;
}

memcpy(parm->eyecatcher, CMS_PARM_EYECATCHER, sizeof(parm->eyecatcher));
memcpy(parm->eyecatcher, CMS_CONFIG_PARM_EXT_EYECATCHER,
sizeof(parm->eyecatcher));
parm->type = type;

switch (type) {
case CMS_CONFIG_PARM_TYPE_CHAR:
{
const char *charValueNullTerm = value;
size_t valueLength = strlen(charValueNullTerm);
if (valueLength > sizeof(parm->charValueNullTerm) - 1) {
if (valueLength > CMS_CONFIG_PARM_EXT_MAX_VALUE_SIZE) {
return RC_CMS_CHAR_PARM_TOO_LONG;
}
parm->valueLength = valueLength;
strcpy(parm->charValueNullTerm, charValueNullTerm);
parm->value = SLHAlloc(slh, valueLength + 1);
if (parm->value == NULL) {
return RC_CMS_SLH_ALLOC_FAILED;
}
strcpy(parm->value, charValueNullTerm);
}
break;
default:
Expand Down Expand Up @@ -1784,6 +1811,9 @@ static int handleConfigService(CrossMemoryServer *server,
return RC_CMS_STDSVC_PARM_NULL;
}

// Copying different versions using the same size is fine because both v0 and
// v2 have the same size, but, if this changes in the future, more complicated
// logic would need to be implemented.
CrossMemoryServerConfigServiceParm localParm;
cmCopyFromSecondaryWithCallerKey(&localParm, callerParm,
sizeof(CrossMemoryServerConfigServiceParm));
Expand All @@ -1793,16 +1823,58 @@ static int handleConfigService(CrossMemoryServer *server,
return RC_CMS_STDSVC_PARM_BAD_EYECATCHER;
}

localParm.nameNullTerm[sizeof(localParm.nameNullTerm) - 1] = '\0';

CrossMemoryServerConfigParm *configParm =
htGet(server->configParms, localParm.nameNullTerm);
if (configParm == NULL) {
return RC_CMS_CONFIG_PARM_NOT_FOUND;
if (localParm.version != CMS_CONFIG_SERVICE_PARM_VERSION_0 &&
localParm.version != CMS_CONFIG_SERVICE_PARM_VERSION_2) {
return RC_CMS_STDSVC_PARM_BAD_VERSION;
}

cmCopyToSecondaryWithCallerKey(&callerParm->result, configParm,
sizeof(callerParm->result));
if (localParm.version == CMS_CONFIG_SERVICE_PARM_VERSION_0) {
localParm.nameNullTerm[sizeof(localParm.nameNullTerm) - 1] = '\0';
CrossMemoryServerConfigParmExt *configParm = htGet(server->configParms,
localParm.nameNullTerm);
if (configParm == NULL) {
return RC_CMS_CONFIG_PARM_NOT_FOUND;
}
size_t valueCopyLength = configParm->type == CMS_CONFIG_PARM_TYPE_CHAR ?
configParm->valueLength + 1 : configParm->valueLength;
if (valueCopyLength > sizeof(localParm.result.charValueNullTerm)) {
return RC_CMS_CONFIG_VALUE_BUF_TOO_SMALL;
}
localParm.result = (CrossMemoryServerConfigParm) {
.eyecatcher = CMS_PARM_EYECATCHER,
.valueLength = configParm->valueLength,
.type = configParm->type,
};
memcpy(localParm.result.charValueNullTerm, configParm->value,
valueCopyLength);
cmCopyToSecondaryWithCallerKey(callerParm, &localParm,
CMS_CONFIG_SERVICE_PARM_SIZE_V0);
} else {
char nameLocalBuffer[CMS_CONFIG_PARM_EXT_MAX_NAME_LENGTH + 1];
if (localParm.ext.nameLength > sizeof(nameLocalBuffer) - 1) {
return RC_CMS_CONFIG_PARM_NAME_TOO_LONG;
}
cmCopyFromSecondaryWithCallerKey(nameLocalBuffer, localParm.ext.name,
localParm.ext.nameLength);
nameLocalBuffer[localParm.ext.nameLength] = '\0';
CrossMemoryServerConfigParmExt *configParm = htGet(server->configParms,
nameLocalBuffer);
if (configParm == NULL) {
return RC_CMS_CONFIG_PARM_NOT_FOUND;
}
size_t valueCopyLength = configParm->type == CMS_CONFIG_PARM_TYPE_CHAR ?
configParm->valueLength + 1 : configParm->valueLength;
localParm.ext.result = *configParm;
localParm.ext.result.value = localParm.ext.valueBuffer;
cmCopyToSecondaryWithCallerKey(callerParm, &localParm,
CMS_CONFIG_SERVICE_PARM_SIZE_V2);
if (valueCopyLength > localParm.ext.valueBufferLength) {
return RC_CMS_CONFIG_VALUE_BUF_TOO_SMALL;
}
cmCopyToSecondaryWithCallerKey(localParm.ext.valueBuffer,
configParm->value,
valueCopyLength);
}

return RC_CMS_OK;
}
Expand Down Expand Up @@ -5335,6 +5407,7 @@ int cmsGetConfigParm(const CrossMemoryServerName *serverName, const char *name,
memcpy(parmList.eyecatcher, CMS_CONFIG_SERVICE_PARM_EYECATCHER,
sizeof(parmList.eyecatcher));
memcpy(parmList.nameNullTerm, name, nameLength);
parmList.version = CMS_CONFIG_SERVICE_PARM_VERSION_0;

int serviceRC = cmsCallService(
serverName,
Expand Down Expand Up @@ -5364,6 +5437,7 @@ int cmsGetConfigParmUnchecked(const CrossMemoryServerName *serverName,
memcpy(parmList.eyecatcher, CMS_CONFIG_SERVICE_PARM_EYECATCHER,
sizeof(parmList.eyecatcher));
memcpy(parmList.nameNullTerm, name, nameLength);
parmList.version = CMS_CONFIG_SERVICE_PARM_VERSION_0;

CrossMemoryServerGlobalArea *cmsGA = NULL;
int getGlobalAreaRC = cmsGetGlobalArea(serverName, &cmsGA);
Expand All @@ -5387,6 +5461,91 @@ int cmsGetConfigParmUnchecked(const CrossMemoryServerName *serverName,
return RC_CMS_OK;
}

int cmsGetConfigParmExt(const CrossMemoryServerName *serverName,
const char *name,
void *valueBuffer,
int valueBufferSize,
CrossMemoryServerConfigParmExt *parm,
int *rsn) {

size_t nameLength = strlen(name);
if (nameLength > CMS_CONFIG_PARM_EXT_MAX_NAME_LENGTH) {
return RC_CMS_CONFIG_PARM_NAME_TOO_LONG;
}

CrossMemoryServerConfigServiceParm parmList = {
.eyecatcher = CMS_CONFIG_SERVICE_PARM_EYECATCHER,
.version = CMS_CONFIG_SERVICE_PARM_VERSION,
.ext.nameLength = nameLength,
.ext.name = name,
.ext.valueBufferLength = valueBufferSize,
.ext.valueBuffer = valueBuffer,
};

int serviceRC = cmsCallService(
serverName,
CROSS_MEMORY_SERVER_CONFIG_SERVICE_ID,
&parmList,
rsn
);
if (serviceRC != RC_CMS_OK) {
if (serviceRC == RC_CMS_CONFIG_VALUE_BUF_TOO_SMALL) {
*parm = parmList.ext.result;
}
return serviceRC;
}

*parm = parmList.ext.result;

return RC_CMS_OK;
}

int cmsGetConfigParmExtUnchecked(const CrossMemoryServerName *serverName,
const char *name,
void *valueBuffer,
int valueBufferSize,
CrossMemoryServerConfigParmExt *parm,
int *rsn) {

size_t nameLength = strlen(name);
if (nameLength > CMS_CONFIG_PARM_EXT_MAX_NAME_LENGTH) {
return RC_CMS_CONFIG_PARM_NAME_TOO_LONG;
}

CrossMemoryServerConfigServiceParm parmList = {
.eyecatcher = CMS_CONFIG_SERVICE_PARM_EYECATCHER,
.version = CMS_CONFIG_SERVICE_PARM_VERSION,
.ext.nameLength = nameLength,
.ext.name = name,
.ext.valueBufferLength = valueBufferSize,
.ext.valueBuffer = valueBuffer,
};

CrossMemoryServerGlobalArea *cmsGA = NULL;
int getGlobalAreaRC = cmsGetGlobalArea(serverName, &cmsGA);
if (getGlobalAreaRC != RC_CMS_OK) {
return getGlobalAreaRC;
}

int serviceRC = cmsCallService3(
cmsGA,
CROSS_MEMORY_SERVER_CONFIG_SERVICE_ID,
&parmList,
CMS_CALL_FLAG_NO_SAF_CHECK,
rsn
);
if (serviceRC != RC_CMS_OK) {
if (serviceRC == RC_CMS_CONFIG_VALUE_BUF_TOO_SMALL) {
*parm = parmList.ext.result;
}
return serviceRC;
}

*parm = parmList.ext.result;

return RC_CMS_OK;
}

int cmsGetPCLogLevel(const CrossMemoryServerName *serverName) {

int logLevel = ZOWE_LOG_NA;
Expand Down
4 changes: 2 additions & 2 deletions c/httpserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2846,9 +2846,9 @@ int extractBasicAuth(HttpRequest *request, HttpHeader *authHeader){
char *authString = NULL;
AUTH_TRACE("start authEnd loop\n");
while ((authEnd < headerLength) && (ebcdicHeader[authEnd] > 0x041)){
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG3, "authEnd=%d\n",authEnd);
authEnd++;
}
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG3, "authEnd=%d\n",authEnd);
authLen = authEnd-authStart;
encodedAuthString = SLHAlloc(slh,authLen+1);
authString = SLHAlloc(slh,authLen+1);
Expand Down Expand Up @@ -2913,8 +2913,8 @@ int extractBearerToken(HttpRequest *request, HttpHeader *authHeader) {
AUTH_TRACE("start tokenEnd loop\n");
while ((tokenEnd < headerLength) && (ebcdicHeader[tokenEnd] > 0x041)){
tokenEnd++;
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG3, "tokenEnd=%d\n", tokenEnd);
}
zowelog(NULL, LOG_COMP_HTTPSERVER, ZOWE_LOG_DEBUG3, "tokenEnd=%d\n", tokenEnd);
const int tokenLen = tokenEnd - tokenStart;
AUTH_TRACE("bearer token length = %d\n", tokenLen);

Expand Down
2 changes: 2 additions & 0 deletions c/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ char *SLHAlloc(ShortLivedHeap *slh, int size){
safeMalloc31(size+4,"SLH Oversize Extend"));
if (bigBlock == NULL){
reportSLHFailure(slh,size);
return NULL;
}
int *sizePtr = (int*)bigBlock;
*sizePtr = size;
Expand All @@ -1528,6 +1529,7 @@ char *SLHAlloc(ShortLivedHeap *slh, int size){
safeMalloc31(slh->blockSize+4,"SLH Extend") );
if (data == NULL){
reportSLHFailure(slh,size);
return NULL;
}
int *sizePtr = (int*)data;
*sizePtr = slh->blockSize;
Expand Down
Loading

0 comments on commit 16f1749

Please sign in to comment.