]> err.no Git - yubikey-personalization/commitdiff
move modifying of ndef struct until after we've checked the length
authorKlas Lindfors <klas@yubico.com>
Thu, 26 Apr 2012 11:38:47 +0000 (13:38 +0200)
committerKlas Lindfors <klas@yubico.com>
Thu, 26 Apr 2012 11:38:47 +0000 (13:38 +0200)
ykpers.c

index c1d133861356e40dbce006849ca2512bc1b0bf01..f913c52fb4609a2a78fd6ff9c821bbde7cebd3fc 100644 (file)
--- a/ykpers.c
+++ b/ykpers.c
@@ -385,16 +385,16 @@ int ykp_construct_ndef_uri(YKNDEF *ndef, const char *uri)
                        break;
                }
        }
-       if(index > num_identifiers) {
-               ndef->data[0] = 0;
-       } else {
-               ndef->data[0] = index + 1;
-       }
        size_t data_length = strlen(uri);
        if(data_length + 1 > NDEF_DATA_SIZE) {
                ykp_errno = YKP_EINVAL;
                return 1;
        }
+       if(index > num_identifiers) {
+               ndef->data[0] = 0;
+       } else {
+               ndef->data[0] = index + 1;
+       }
        memcpy(ndef->data + 1, uri, data_length);
        ndef->len = data_length + 1;
        ndef->type = 'U';