Skip to content

Commit 9682df9

Browse files
authored
Merge pull request #511 from libtom/more-fixes
More fixes
2 parents fcdb14e + 68cc580 commit 9682df9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+142
-132
lines changed

demos/aesgcm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static void scan_hex(const char* str, uint8_t* bytes, size_t blen)
8282
0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, /* `abcdefg */
8383
};
8484

85-
for (pos = 0; ((pos < (blen*2)) && (pos < strlen(str))); pos += 2)
85+
for (pos = 0; ((pos < (blen*2)) && (pos < XSTRLEN(str))); pos += 2)
8686
{
8787
idx0 = (uint8_t)(str[pos+0] & 0x1F) ^ 0x10;
8888
idx1 = (uint8_t)(str[pos+1] & 0x1F) ^ 0x10;
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
118118

119119
if (fsize(in_file) <= 0) die(__LINE__);
120120

121-
keylen = strlen(key_string);
121+
keylen = XSTRLEN(key_string);
122122
if (keylen != 96) die(__LINE__);
123123

124124
scan_hex(key_string, keybuf, sizeof(keybuf));

demos/ltcrypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int main(int argc, char *argv[])
122122
if(fgets((char *)tmpkey,sizeof(tmpkey), stdin) == NULL)
123123
exit(-1);
124124
outlen = sizeof(key);
125-
if ((err = hash_memory(hash_idx,tmpkey,strlen((char *)tmpkey),key,&outlen)) != CRYPT_OK) {
125+
if ((err = hash_memory(hash_idx,tmpkey,XSTRLEN((char *)tmpkey),key,&outlen)) != CRYPT_OK) {
126126
printf("Error hashing key: %s\n", error_to_string(err));
127127
exit(-1);
128128
}

demos/openssl-enc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ int main(int argc, char *argv[]) {
332332

333333
/* Run the key derivation from the provided passphrase. This gets us
334334
the key and iv. */
335-
ret = pkcs_5_alg1_openssl((unsigned char*)argv[4], strlen(argv[4]), salt,
335+
ret = pkcs_5_alg1_openssl((unsigned char*)argv[4], XSTRLEN(argv[4]), salt,
336336
OPENSSL_ITERATIONS, hash, keyiv, &keyivlen );
337337
if(ret != CRYPT_OK)
338338
BARF("Could not derive key/iv from passphrase");

helper.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sub check_source {
5454
push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bmemcmp\s*\(/;
5555
push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bstrcmp\s*\(/;
5656
push @{$troubles->{unwanted_strcpy}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bstrcpy\s*\(/;
57+
push @{$troubles->{unwanted_strlen}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bstrlen\s*\(/;
5758
push @{$troubles->{unwanted_strncpy}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bstrncpy\s*\(/;
5859
push @{$troubles->{unwanted_clock}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bclock\s*\(/;
5960
push @{$troubles->{unwanted_qsort}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bqsort\s*\(/;

src/ciphers/tea.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ int tea_test(void)
160160
zeromem(&skey, sizeof(skey));
161161

162162
l = sizeof(key);
163-
if ((err = base16_decode(tests[i].key, strlen(tests[i].key), key, &l)) != CRYPT) return err;
163+
if ((err = base16_decode(tests[i].key, XSTRLEN(tests[i].key), key, &l)) != CRYPT) return err;
164164
l = sizeof(ptct[0]);
165-
if ((err = base16_decode(tests[i].pt, strlen(tests[i].pt), ptct[0], &l)) != CRYPT) return err;
165+
if ((err = base16_decode(tests[i].pt, XSTRLEN(tests[i].pt), ptct[0], &l)) != CRYPT) return err;
166166
l = sizeof(ptct[1]);
167-
if ((err = base16_decode(tests[i].ct, strlen(tests[i].ct), ptct[1], &l)) != CRYPT) return err;
167+
if ((err = base16_decode(tests[i].ct, XSTRLEN(tests[i].ct), ptct[1], &l)) != CRYPT) return err;
168168

169169
if ((err = tea_setup(key, 16, 0, &skey)) != CRYPT_OK) {
170170
return err;

src/encauth/chachapoly/chacha20poly1305_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int chacha20poly1305_test(void)
3131
0x61, 0x16 };
3232
unsigned char tag[] = { 0x1A, 0xE1, 0x0B, 0x59, 0x4F, 0x09, 0xE2, 0x6A, 0x7E, 0x90, 0x2E, 0xCB, 0xD0, 0x60, 0x06, 0x91 };
3333
char m[] = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
34-
unsigned long mlen = strlen(m);
34+
unsigned long mlen = XSTRLEN(m);
3535
unsigned long len;
3636
unsigned char rfc7905_pt[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
3737
unsigned char rfc7905_enc[] = { 0xE4, 0x62, 0x85, 0xB4, 0x29, 0x95, 0x34, 0x96, 0xAB, 0xFB, 0x67, 0xCD, 0xAE, 0xAC, 0x94, 0x1E };

src/hashes/blake2b.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ int blake2b_512_test(void)
480480

481481
for (i = 0; tests[i].msg != NULL; i++) {
482482
blake2b_512_init(&md);
483-
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
483+
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
484484
blake2b_done(&md, tmp);
485485
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_512", i)) {
486486
return CRYPT_FAIL_TESTVECTOR;
@@ -527,7 +527,7 @@ int blake2b_384_test(void)
527527

528528
for (i = 0; tests[i].msg != NULL; i++) {
529529
blake2b_384_init(&md);
530-
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
530+
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
531531
blake2b_done(&md, tmp);
532532
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_384", i)) {
533533
return CRYPT_FAIL_TESTVECTOR;
@@ -580,7 +580,7 @@ int blake2b_256_test(void)
580580

581581
for (i = 0; tests[i].msg != NULL; i++) {
582582
blake2b_256_init(&md);
583-
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
583+
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
584584
blake2b_done(&md, tmp);
585585
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_256", i)) {
586586
return CRYPT_FAIL_TESTVECTOR;
@@ -621,7 +621,7 @@ int blake2b_160_test(void)
621621

622622
for (i = 0; tests[i].msg != NULL; i++) {
623623
blake2b_160_init(&md);
624-
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
624+
blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
625625
blake2b_done(&md, tmp);
626626
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_160", i)) {
627627
return CRYPT_FAIL_TESTVECTOR;

src/hashes/blake2s.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int blake2s_256_test(void)
470470

471471
for (i = 0; tests[i].msg != NULL; i++) {
472472
blake2s_256_init(&md);
473-
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
473+
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
474474
blake2s_done(&md, tmp);
475475
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2S_256", i)) {
476476
return CRYPT_FAIL_TESTVECTOR;
@@ -514,7 +514,7 @@ int blake2s_224_test(void)
514514

515515
for (i = 0; tests[i].msg != NULL; i++) {
516516
blake2s_224_init(&md);
517-
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
517+
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
518518
blake2s_done(&md, tmp);
519519
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2S_224", i)) {
520520
return CRYPT_FAIL_TESTVECTOR;
@@ -556,7 +556,7 @@ int blake2s_160_test(void)
556556

557557
for (i = 0; tests[i].msg != NULL; i++) {
558558
blake2s_160_init(&md);
559-
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
559+
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
560560
blake2s_done(&md, tmp);
561561
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2S_160", i)) {
562562
return CRYPT_FAIL_TESTVECTOR;
@@ -596,7 +596,7 @@ int blake2s_128_test(void)
596596

597597
for (i = 0; tests[i].msg != NULL; i++) {
598598
blake2s_128_init(&md);
599-
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
599+
blake2s_process(&md, (unsigned char *)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
600600
blake2s_done(&md, tmp);
601601
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2S_128", i)) {
602602
return CRYPT_FAIL_TESTVECTOR;

src/hashes/chc/chc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ int chc_test(void)
287287
if ((err = chc_init(&md)) != CRYPT_OK) {
288288
return err;
289289
}
290-
if ((err = chc_process(&md, tests[i].msg, strlen((char *)tests[i].msg))) != CRYPT_OK) {
290+
if ((err = chc_process(&md, tests[i].msg, XSTRLEN((char *)tests[i].msg))) != CRYPT_OK) {
291291
return err;
292292
}
293293
if ((err = chc_done(&md, tmp)) != CRYPT_OK) {

src/hashes/md2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int md2_test(void)
232232

233233
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
234234
md2_init(&md);
235-
md2_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
235+
md2_process(&md, (unsigned char*)tests[i].msg, (unsigned long)XSTRLEN(tests[i].msg));
236236
md2_done(&md, tmp);
237237
if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "MD2", i)) {
238238
return CRYPT_FAIL_TESTVECTOR;

0 commit comments

Comments
 (0)