Skip to content

Guard the CurrentUnixTime global, so Security and JsonWebToken can be used together - #5

Open
mckuipers wants to merge 4 commits into
DataFlex-dev:production/stablefrom
mckuipers:fix/guard-currentunixtime-global-redefinition
Open

Guard the CurrentUnixTime global, so Security and JsonWebToken can be used together#5
mckuipers wants to merge 4 commits into
DataFlex-dev:production/stablefrom
mckuipers:fix/guard-currentunixtime-global-redefinition

Conversation

@mckuipers

Copy link
Copy Markdown

include/UnixTime.pkg guards its other five definitions — gVoid, tFileTime, tSystemTime,
and both External_Functions — but Function CurrentUnixTime Global has no #IFNDEF around
it. This adds the missing one.

Why it matters

DataFlex-dev/JsonWebToken ships a byte-identical copy of this file as JWT/UnixTime.pkg,
also unguarded. DataFlex resolves a Use by path, so to the compiler these are two unrelated
files, and any program containing both gets the global twice:

Error 4390: Illegal method name definition
            Global method GET CURRENTUNIXTIME already defined

That combination is not exotic — it is what the OAuth Server Lib needs. OAuth Server Lib
requires JsonWebToken, and any OIDC provider offering TOTP as a second factor also wants
cSecureOneTimePassword from this library. The first build that puts TOTP and JWT in one
program fails, and the error points into a package-manager-installed folder that cannot be
edited, so it reads like a broken dependency rather than a name collision.

Reproduce

Build any program that uses cSecureOneTimePassword and JWT.pkg together.

Why Get_CurrentUnixTime is the right symbol

A Function <Name> Global defines Get_<Name>. The precedent is DataFlex's own
cWorkspace.pkg, which guards Function LastDelimeter Global with #IFDEF Get_LastDelimeter.

I used this file's existing #IFNDEF … #ENDIF style rather than cWorkspace.pkg's
#IFDEF … #ELSE … #ENDIF, to match the five guards already here.

Verification

Compiled this patched file into a program that already defines CurrentUnixTime:

  • BeforeError 4390 at UnixTime.pkg (40,1).
  • After — clean compile; the guard skips the definition.

The same build also asserts the symbol name is right rather than assuming it, via

#IFNDEF Get_CurrentUnixTime
    #ERROR 999 Get_CurrentUnixTime is NOT the symbol
#ENDIF
#IFDEF Get_CurrentUnixTimeNeverDefinedAnywhere
    #ERROR 998 IFDEF matched an undefined symbol
#ENDIF

placed after a known definition. Neither #ERROR fires — the second one is there so the first
cannot pass vacuously.

The matching PR on JsonWebToken

Guarding either copy fixes the collision, but both should have one so neither library depends
on Use order. The matching one-line PR is going up on DataFlex-dev/JsonWebToken as well.

Base branch

Raised against 26-0-package-manager. This file is the identical blob on production/stable,
and the commit cherry-picks there cleanly — verified — so it can land on either.

HarmWibier and others added 4 commits January 22, 2026 14:56
BCryptDuplicateHash and BCryptDuplicateKey fetched BCRYPT_PROVIDER_HANDLE
via BCryptNamedUIntegerPropertyValue, which only accepts 4-byte values.
BCRYPT_PROVIDER_HANDLE is a native Handle, 8 bytes on x64, so the size
check silently returned 0 and the next BCryptGetProperty call
dereferenced a null handle.

Both call sites now fetch the handle via raw BCryptNamedPropertyValue
and copy it in only when the returned size matches SizeOfType(Handle).

BCryptGetProperty's blanket 8-to-4 truncation is removed since it was
corrupting the newly fetched 8-byte handle. The same tolerance is
re-added scoped to BCryptNamedUIntegerPropertyValue, the one caller
that legitimately wants 4 bytes. NCryptNamedUIntegerPropertyValue gets
the same tolerance for symmetry, though it has no current callers.
…ge-manager

Fix BCRYPT_PROVIDER_HANDLE access violation in CNG.pkg
include/UnixTime.pkg guards its other five definitions - gVoid, tFileTime,
tSystemTime, and the two External_Functions - but `Function CurrentUnixTime
Global` had no #IFNDEF around it.

That makes the library uncombinable with DataFlex-dev/JsonWebToken, which
ships a byte-identical copy of this file as JWT/UnixTime.pkg, also
unguarded. DataFlex resolves a Use by path, so to the compiler these are two
unrelated files and the global is defined twice:

    Error 4390: Illegal method name definition
                Global method GET CURRENTUNIXTIME already defined

Reproduce by building any program that uses cSecureOneTimePassword (TOTP)
and JWT together - which is what the OAuth Server Lib needs, since it
requires JsonWebToken and any OIDC provider offering a second factor wants
both.

Get_CurrentUnixTime is the symbol a `Function ... Global` defines; the
precedent is DataFlex's own cWorkspace.pkg, which guards `Function
LastDelimeter Global` with `#IFDEF Get_LastDelimeter`. Verified by
compiling this file into a program that already defines CurrentUnixTime:
4390 before, clean after.

Guarding either copy is enough to fix the collision, but both should have
one so neither depends on Use order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants