zowe / zowe-common-c

C Libraries for various OS & Networking needs
Eclipse Public License 2.0
10 stars 30 forks source link

ChangeTag prints garbage #426

Open Martin-Zeithaml opened 7 months ago

Martin-Zeithaml commented 7 months ago

How to replicate

Simple testcht.js:

import * as zos from 'zos'
let result = zos.changeTag('./a.txt', 0);

File a.txt exists, t ISO8859-1 T=on a.txt.

Running the script:

zowe/bin/utils/configmgr -script testcht.js
��/��ʀ�/�%������ǀ���>?���

The garbage on the screen is printed here.

Problem 1

printf is for some reason producing garbage.

Example

When the error message was changed: printf("abcd0123") will produce X'2FC2C4C0 90911693' Is this encoding problem?

Problem 2

It does not work, the js code should remove the tag, which remains unchanged.

1000TurquoisePogs commented 6 months ago

This isn't what I thought at first. changeTag DOES work - sometimes. if you do 1047 instead of 0, it works. It looks like basically any number except 0 works. There's some edge case around 0 (remove tag) When it works it does not print garbage.

1000TurquoisePogs commented 6 months ago

i think the cause is here https://github.com/JoeNemo/quickjs-portable/blob/main/porting/polyfill.c#L142 the conditional says text or binary. 0 is neither.

Martin-Zeithaml commented 6 months ago

I have noticed this difference, when used zos.zstat for

This seems to help:

#define CCSID_NONE 0
...
  if (ccsid == CCSID_NONE || ccsid == CCSID_BINARY ) {
    attr.att_filetag.ft_txtflag = 0;
  } else {
    attr.att_filetag.ft_txtflag = 1;
  }

However the printf problem remains.

Martin-Zeithaml commented 6 months ago

printf of EBCDIC hex code is working: printf("\xC8\x85\x93\x93\x96\x6B\x40\xA6\x96\x99\x93\x84\x5A"); -> Hello, world!

I am guessing, this is some #define, compiler option or something missing.

Martin-Zeithaml commented 6 months ago

toEBCDIC or printf2 should help.

Martin-Zeithaml commented 6 months ago

https://github.com/JoeNemo/quickjs-portable/pull/6

Martin-Zeithaml commented 6 months ago

Problem 1

Garbage on the screen remains. Most likely caused by not using printf2. This can be reproduced when __chattr will fail, e.g. zos.changeTag('file which does not exist', 0);

Problem 2

Merged, working fine.