Update pin.c

This commit is contained in:
Token2
2024-11-21 21:35:49 +01:00
committed by GitHub
parent dc7a4c9455
commit 1593cba5a4

View File

@@ -80,6 +80,7 @@ out:
int pin_set2(char *path, const char *pin1) { int pin_set2(char *path, const char *pin1) {
fido_dev_t *dev = NULL; fido_dev_t *dev = NULL;
char mutable_pin[64]; // Temporary buffer for mutable PIN
int r, status = 1; int r, status = 1;
if (strlen(pin1) < 4 || strlen(pin1) > 63) { if (strlen(pin1) < 4 || strlen(pin1) > 63) {
@@ -87,28 +88,36 @@ out:
return status; return status;
} }
// Copy the PIN to a mutable buffer
strncpy(mutable_pin, pin1, sizeof(mutable_pin) - 1);
mutable_pin[sizeof(mutable_pin) - 1] = '\0'; // Null-terminate
dev = open_dev(path); dev = open_dev(path);
if (!dev) { if (!dev) {
fprintf(stderr, "Failed to open device\n"); fprintf(stderr, "Failed to open device\n");
return status; return status;
} }
r = fido_dev_set_pin(dev, pin1, NULL); r = fido_dev_set_pin(dev, mutable_pin, NULL);
if (r != FIDO_OK) { if (r != FIDO_OK) {
fprintf(stderr, "Error setting PIN: %s\n", fido_strerr(r)); fprintf(stderr, "Error setting PIN: %s\n", fido_strerr(r));
goto out; goto out;
} }
status = 0; // Success status = 0; // Success
out: out:
if (dev) { if (dev) {
fido_dev_close(dev); fido_dev_close(dev);
fido_dev_free(&dev); fido_dev_free(&dev);
} }
explicit_bzero((void *)pin1, strlen(pin1)); // Clear PIN from memory
// Clear the PIN from memory
explicit_bzero(mutable_pin, sizeof(mutable_pin));
return status; return status;
} }
int int
pin_change(char *path) pin_change(char *path)
{ {