rename local ctxp -> contextp to avoid global ctxp

This commit is contained in:
Keni
2024-12-01 11:25:16 -08:00
parent dda5d03d91
commit 9777e7785a
+43 -43
View File
@@ -799,7 +799,7 @@ struct CRctxt *ctxp = &ctxp_; // XXX should this now be in gc.* ?
#define win32err(fn) errname = fn; goto error #define win32err(fn) errname = fn; goto error
int int
win32_cr_helper(char cmd, struct CRctxt *ctxp, void *p, int d){ win32_cr_helper(char cmd, struct CRctxt *contextp, void *p, int d){
char *errname = "unknown"; char *errname = "unknown";
switch (cmd) { switch (cmd) {
default: default:
@@ -815,77 +815,77 @@ win32_cr_helper(char cmd, struct CRctxt *ctxp, void *p, int d){
return MessageBoxW(NULL, lbidstr, L"bidshow", MB_SETFOREGROUND); return MessageBoxW(NULL, lbidstr, L"bidshow", MB_SETFOREGROUND);
} }
break; break;
case 'i': /* HASH_INIT(ctxp) */ case 'i': /* HASH_INIT(contextp) */
if (!IsWindowsVistaOrGreater()) if (!IsWindowsVistaOrGreater())
return 1; // CNG not available. return 1; // CNG not available.
ctxp->bah = NULL; contextp->bah = NULL;
ctxp->bhh = NULL; contextp->bhh = NULL;
ctxp->pbhashobj = NULL; contextp->pbhashobj = NULL;
ctxp->cbhashobj = 0; contextp->cbhashobj = 0;
ctxp->cbhash = 0; contextp->cbhash = 0;
ctxp->cbdata = 0; contextp->cbdata = 0;
ctxp->pbhash = NULL; contextp->pbhash = NULL;
ctxp->st = 0; contextp->st = 0;
// win32err("test"); // TESTING - FAKE AN ERROR // win32err("test"); // TESTING - FAKE AN ERROR
if (0 > (ctxp->st = BCryptOpenAlgorithmProvider( if (0 > (contextp->st = BCryptOpenAlgorithmProvider(
&ctxp->bah, BCRYPT_MD4_ALGORITHM, NULL, 0))) { &contextp->bah, BCRYPT_MD4_ALGORITHM, NULL, 0))) {
win32err("BCryptOpenAlgorithmProvider"); win32err("BCryptOpenAlgorithmProvider");
}; };
if (0 > (ctxp->st = if (0 > (contextp->st =
BCryptGetProperty(ctxp->bah, BCRYPT_OBJECT_LENGTH, BCryptGetProperty(contextp->bah, BCRYPT_OBJECT_LENGTH,
(unsigned char *) &ctxp->cbhashobj, (unsigned char *) &contextp->cbhashobj,
sizeof(DWORD), &ctxp->cbdata, 0))) { sizeof(DWORD), &contextp->cbdata, 0))) {
win32err("BCryptGetProperty1"); win32err("BCryptGetProperty1");
}; };
if (0 if (0
== (ctxp->pbhashobj = == (contextp->pbhashobj =
HeapAlloc(GetProcessHeap(), 0, ctxp->cbhashobj))) { HeapAlloc(GetProcessHeap(), 0, contextp->cbhashobj))) {
win32err("HeapAlloc1"); win32err("HeapAlloc1");
}; };
if (0 > (ctxp->st = BCryptGetProperty( if (0 > (contextp->st = BCryptGetProperty(
ctxp->bah, BCRYPT_HASH_LENGTH, (PBYTE) &ctxp->cbhash, contextp->bah, BCRYPT_HASH_LENGTH, (PBYTE) &contextp->cbhash,
sizeof(DWORD), &ctxp->cbdata, 0))) { sizeof(DWORD), &contextp->cbdata, 0))) {
win32err("BCryptGetProperty2"); win32err("BCryptGetProperty2");
} }
if (0 if (0
== (ctxp->pbhash = == (contextp->pbhash =
HeapAlloc(GetProcessHeap(), 0, ctxp->cbhash))) { HeapAlloc(GetProcessHeap(), 0, contextp->cbhash))) {
win32err("HeapAlloc2\n"); win32err("HeapAlloc2\n");
} }
if (0 > BCryptCreateHash(ctxp->bah, &ctxp->bhh, ctxp->pbhashobj, if (0 > BCryptCreateHash(contextp->bah, &contextp->bhh, contextp->pbhashobj,
ctxp->cbhashobj, NULL, 0, 0)) { contextp->cbhashobj, NULL, 0, 0)) {
win32err("BCryptCreateHash"); win32err("BCryptCreateHash");
} }
break; break;
case 'u': /* HASH_UPDATE(ctxp, ptr, len) */ case 'u': /* HASH_UPDATE(contextp, ptr, len) */
if (0 > (ctxp->st = BCryptHashData(ctxp->bhh, p, d, 0))) { if (0 > (contextp->st = BCryptHashData(contextp->bhh, p, d, 0))) {
win32err("BCryptHashData"); win32err("BCryptHashData");
} }
break; break;
case 'f': /* HASH_FINISH(ctxp) */ case 'f': /* HASH_FINISH(contextp) */
if (0 > BCryptFinishHash(ctxp->bhh, ctxp->pbhash, ctxp->cbhash, 0)) { if (0 > BCryptFinishHash(contextp->bhh, contextp->pbhash, contextp->cbhash, 0)) {
win32err("BCryptFinishHash"); win32err("BCryptFinishHash");
} }
break; break;
case 'c': /* HASH_CLEANUP(ctxp) */ case 'c': /* HASH_CLEANUP(contextp) */
if (ctxp->bah) { if (contextp->bah) {
BCryptCloseAlgorithmProvider(ctxp->bah, 0); BCryptCloseAlgorithmProvider(contextp->bah, 0);
} }
if (ctxp->bhh) { if (contextp->bhh) {
BCryptDestroyHash(ctxp->bhh); BCryptDestroyHash(contextp->bhh);
} }
if (ctxp->pbhashobj) { if (contextp->pbhashobj) {
HeapFree(GetProcessHeap(), 0, ctxp->pbhashobj); HeapFree(GetProcessHeap(), 0, contextp->pbhashobj);
} }
if (ctxp->pbhash) { if (contextp->pbhash) {
HeapFree(GetProcessHeap(), 0, ctxp->pbhash); HeapFree(GetProcessHeap(), 0, contextp->pbhash);
} }
break; break;
case 's': /* HASH_RESULT_SIZE(ctxp) */ case 's': /* HASH_RESULT_SIZE(contextp) */
return ctxp->cbhash; return contextp->cbhash;
case 'r': /* HASH_RESULT(ctxp, resp) */ case 'r': /* HASH_RESULT(contextp, resp) */
*(unsigned char **)p = ctxp->pbhash; *(unsigned char **)p = contextp->pbhash;
break; break;
case 'b': /* HASH_BINFILE(NULL,&binfile,0) */ case 'b': /* HASH_BINFILE(NULL,&binfile,0) */
// XXX This buffer should be allocated, not static (and freed in // XXX This buffer should be allocated, not static (and freed in
@@ -906,7 +906,7 @@ win32_cr_helper(char cmd, struct CRctxt *ctxp, void *p, int d){
return 0; /* ok */ return 0; /* ok */
error: error:
raw_printf("WIN32 function %s failed: status=%" PRIx64 "\n", raw_printf("WIN32 function %s failed: status=%" PRIx64 "\n",
errname, (uint64)ctxp->st); errname, (uint64)contextp->st);
return 1; /* fail */ return 1; /* fail */
} }
#undef win32err #undef win32err