From d2d63086b2a43bb93a6edabcc2aa0e9b082bb260 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Fri, 17 May 2024 15:06:36 +0200 Subject: [PATCH 1/3] Return error for wrong file Signed-off-by: Martin Zeithaml --- c/embeddedjs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/c/embeddedjs.c b/c/embeddedjs.c index aad75a32d..bbbb6fac7 100644 --- a/c/embeddedjs.c +++ b/c/embeddedjs.c @@ -626,7 +626,14 @@ static JSValue xplatformLoadFileUTF8(JSContext *ctx, JSValueConst this_val, JS_ToInt32(ctx, &sourceCCSID, argv[1]); buf = (char*)js_load_file(ctx, &length, filename); - + if (!buf) { + size_t filenameNativeLen = strlen(filename); + char filenameNative[filenameNativeLen + 1]; + snprintf(filenameNative, filenameNativeLen + 1, "%.*s", (int)filenameNativeLen, filename); + convertToNative(filenameNative, (int)filenameNativeLen); + perror(filenameNative); + return JS_EXCEPTION; + } if (sourceCCSID < 0){ char *nativeBuffer = safeMalloc(length+1,"xplatformStringFromBytes"); memcpy(nativeBuffer,buf,length); From 37677a60ea4976262390a05b00a62ed2369e1165 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Mon, 20 May 2024 09:42:49 +0200 Subject: [PATCH 2/3] Remove unused vars and error consistent Signed-off-by: Martin Zeithaml --- c/embeddedjs.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/c/embeddedjs.c b/c/embeddedjs.c index bbbb6fac7..e2697fc0d 100644 --- a/c/embeddedjs.c +++ b/c/embeddedjs.c @@ -612,7 +612,6 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename); /* (filename, ccsid) ccsid -1 implies guess best for platform, 0 implies don't translate */ static JSValue xplatformLoadFileUTF8(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv){ - size_t size; size_t length; char *buf; @@ -627,11 +626,6 @@ static JSValue xplatformLoadFileUTF8(JSContext *ctx, JSValueConst this_val, buf = (char*)js_load_file(ctx, &length, filename); if (!buf) { - size_t filenameNativeLen = strlen(filename); - char filenameNative[filenameNativeLen + 1]; - snprintf(filenameNative, filenameNativeLen + 1, "%.*s", (int)filenameNativeLen, filename); - convertToNative(filenameNative, (int)filenameNativeLen); - perror(filenameNative); return JS_EXCEPTION; } if (sourceCCSID < 0){ @@ -685,7 +679,6 @@ static int appendToFile(char *filename, const char *data, int length) { /* (filename, ccsid) ccsid -1 implies guess best for platform, 0 implies don't translate */ static JSValue xplatformAppendFileUTF8(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv){ - size_t size; size_t length; NATIVE_STR(filename,nativeFilename,0); @@ -725,7 +718,6 @@ static JSValue xplatformAppendFileUTF8(JSContext *ctx, JSValueConst this_val, /* (filename, ccsid) ccsid -1 implies guess best for platform, 0 implies don't translate */ static JSValue xplatformStoreFileUTF8(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv){ - size_t size; size_t length; NATIVE_STR(filename,nativeFilename,0); From 8b37e0536934d0f18dcb281595e815bdef560199 Mon Sep 17 00:00:00 2001 From: Martin Zeithaml Date: Mon, 20 May 2024 09:50:42 +0200 Subject: [PATCH 3/3] Changelog note Signed-off-by: Martin Zeithaml --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7aa2223..47c6c5f13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Zowe Common C Changelog +## `2.17.0` +- Fixed `xplatform.loadFileUTF8` when trying to open nonexistent file (#454) + ## `2.16.0` - No yaml value converted to null (#442) - Added `zos.getZosVersion()` and `zos.getEsm()` calls for configmgr QJS (#429)