cleanups, make clang happy

This commit is contained in:
cathugger 2019-03-15 21:04:40 +00:00
parent 9ac54f6db3
commit 390e8ea9de
No known key found for this signature in database
GPG key ID: 9BADDA2DAF6F01A8
11 changed files with 44 additions and 34 deletions

View file

@ -1,7 +1,7 @@
// converts src[0:slen] to base64 string // converts src[0:slen] to base64 string
char *base64_to(char *dst,const u8 *src,size_t slen); char *base64_to(char *dst,const u8 *src,size_t slen);
// calculates length needed to store data converted to base64 // calculates length needed to store data converted to base64
#define BASE64_TO_LEN(l) (((l + 3 - 1) / 3) * 4) #define BASE64_TO_LEN(l) ((((l) + 2) / 3) * 4)
// converts src string from base64 // converts src string from base64
size_t base64_from(u8 *dst,const char *src,size_t slen); size_t base64_from(u8 *dst,const char *src,size_t slen);
// calculates length needed to store data converted from base64 // calculates length needed to store data converted from base64

View file

@ -10,7 +10,7 @@
#define FORMATTED_PUBLIC_LEN (PKPREFIX_SIZE + PUBLIC_LEN) #define FORMATTED_PUBLIC_LEN (PKPREFIX_SIZE + PUBLIC_LEN)
#define FORMATTED_SECRET_LEN (SKPREFIX_SIZE + SECRET_LEN) #define FORMATTED_SECRET_LEN (SKPREFIX_SIZE + SECRET_LEN)
// full onion address, WITHOUT newline // full onion address, WITHOUT newline or terminating nil char
#define ONION_LEN 62 #define ONION_LEN 62
extern pthread_mutex_t fout_mutex; extern pthread_mutex_t fout_mutex;

View file

@ -186,7 +186,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[cstd="$cstd -Wall"], [cstd="$cstd -Wall"],
[AC_MSG_RESULT([no])] [AC_MSG_RESULT([no])]
) )
CFLAGS="$cstd -Wno-maybe-uninitialized" # (negative) detection on clang fails without -Werror
CFLAGS="$cstd -Wno-maybe-uninitialized -Werror"
AC_MSG_CHECKING([whether CC supports -Wno-maybe-uninitialized]) AC_MSG_CHECKING([whether CC supports -Wno-maybe-uninitialized])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes])] [AC_MSG_RESULT([yes])]

View file

@ -11,8 +11,10 @@ static const ge25519_niels ge25519_base_multiples_niels[] = {
#endif #endif
}; };
#ifdef SMALLTABLES
/* d */ /* d */
static const fe25519 ecd = {{0x75EB4DCA135978A3, 0x00700A4D4141D8AB, 0x8CC740797779E898, 0x52036CEE2B6FFE73}}; static const fe25519 ecd = {{0x75EB4DCA135978A3, 0x00700A4D4141D8AB, 0x8CC740797779E898, 0x52036CEE2B6FFE73}};
#endif
void ge25519_scalarmult_base(ge25519_p3 *r, const sc25519 *s) void ge25519_scalarmult_base(ge25519_p3 *r, const sc25519 *s)
{ {

View file

@ -10,15 +10,21 @@
struct texttestcase { struct texttestcase {
const char *in; const char *in;
const char *out; const char *out;
const char *rev;
} tests0[] = { } tests0[] = {
{"", "", ""}, { "" ,"" },
{"f", "Zg==", "f"}, { "f" ,"Zg==" },
{"fo", "Zm8=", "fo"}, { "fo" ,"Zm8=" },
{"foo", "Zm9v", "foo"}, { "foo" ,"Zm9v" },
{"foob", "Zm9vYg==", "foob"}, { "foob" ,"Zm9vYg==" },
{"fooba", "Zm9vYmE=", "fooba"}, { "fooba" ,"Zm9vYmE=" },
{"foobar", "Zm9vYmFy", "foobar"}, { "foobar","Zm9vYmFy" },
{ "foobarf" ,"Zm9vYmFyZg==" },
{ "foobarfo" ,"Zm9vYmFyZm8=" },
{ "foobarfoo" ,"Zm9vYmFyZm9v" },
{ "foobarfoob" ,"Zm9vYmFyZm9vYg==" },
{ "foobarfooba" ,"Zm9vYmFyZm9vYmE=" },
{ "foobarfoobar","Zm9vYmFyZm9vYmFy" },
}; };
int main(void) int main(void)
@ -32,16 +38,21 @@ int main(void)
tests0[i].in, buf, tests0[i].out); tests0[i].in, buf, tests0[i].out);
return 1; return 1;
} }
if (strlen(buf) != BASE64_TO_LEN(strlen(tests0[i].in))) {
printf("encoded length mismatch: got %d expected %d\n",
(int) strlen(buf), (int) BASE64_TO_LEN(strlen(tests0[i].in)));
return 1;
}
if (!base64_valid(buf,0)) { if (!base64_valid(buf,0)) {
printf("encoded data is considered invalid\n"); printf("encoded data is considered invalid\n");
return 3; return 1;
} }
r = base64_from((u8 *)buf2, buf, strlen(buf)); r = base64_from((u8 *)buf2, buf, strlen(buf));
buf2[r] = '\0'; buf2[r] = '\000';
if (strcmp(buf2, tests0[i].rev) != 0) { if (strcmp(buf2, tests0[i].in) != 0) {
printf("invalid decoding result: encoded \"%s\", decoded as \"%s\", but expected \"%s\".\n", printf("invalid decoding result: encoded \"%s\", decoded as \"%s\", but expected \"%s\".\n",
tests0[i].out, buf2, tests0[i].rev); tests0[i].out, buf2, tests0[i].in);
return 2; return 1;
} }
} }
return 0; return 0;

20
yaml.c
View file

@ -37,19 +37,13 @@ static const char keys_field_time[] = "time: ";
#define KEYS_FIELD_SECRETKEY_LEN (sizeof(keys_field_secretkey) - NULLTERM_LEN) #define KEYS_FIELD_SECRETKEY_LEN (sizeof(keys_field_secretkey) - NULLTERM_LEN)
#define KEYS_FIELD_TIME_LEN (sizeof(keys_field_time) - NULLTERM_LEN) #define KEYS_FIELD_TIME_LEN (sizeof(keys_field_time) - NULLTERM_LEN)
static const char hostname_example[] = "xxxxxvsjzke274nisktdqcl3eqm5ve3m6iur6vwme7m5p6kxivrvjnyd.onion"; #define B64_PUBKEY_LEN (BASE64_TO_LEN(FORMATTED_PUBLIC_LEN))
static const char pubkey_example[] = "PT0gZWQyNTUxOXYxLXB1YmxpYzogdHlwZTAgPT0AAAC973vWScqJr/GokqY4CXskGdqTbPIpH1bMJ9nX+VdFYw=="; #define B64_SECKEY_LEN (BASE64_TO_LEN(FORMATTED_SECRET_LEN))
static const char seckey_example[] = "PT0gZWQyNTUxOXYxLXNlY3JldDogdHlwZTAgPT0AAACwCPMr6rvBRtkW7ZzZ8P7Ne4acRZrhPrN/EF6AETRraFGvdrkW5es4WXB2UxrbuUf8zPoIKkXK5cpdakYdUeM3"; #define TIME_LEN (21 * sizeof(char)) // strlen("2018-07-04 21:31:20 Z")
static const char time_example[] = "2018-07-04 21:31:20 Z";
#define HOSTNAME_LEN (sizeof(hostname_example) - NULLTERM_LEN)
#define B64_PUBKEY_LEN (sizeof(pubkey_example) - NULLTERM_LEN)
#define B64_SECKEY_LEN (sizeof(seckey_example) - NULLTERM_LEN)
#define TIME_LEN (sizeof(time_example) - NULLTERM_LEN)
#define KEYS_LEN ( \ #define KEYS_LEN ( \
KEYS_FIELD_GENERATED_LEN + LINEFEED_LEN + \ KEYS_FIELD_GENERATED_LEN + LINEFEED_LEN + \
KEYS_FIELD_HOSTNAME_LEN + HOSTNAME_LEN + LINEFEED_LEN + \ KEYS_FIELD_HOSTNAME_LEN + ONION_LEN + LINEFEED_LEN + \
KEYS_FIELD_PUBLICKEY_LEN + B64_PUBKEY_LEN + LINEFEED_LEN + \ KEYS_FIELD_PUBLICKEY_LEN + B64_PUBKEY_LEN + LINEFEED_LEN + \
KEYS_FIELD_SECRETKEY_LEN + B64_SECKEY_LEN + LINEFEED_LEN + \ KEYS_FIELD_SECRETKEY_LEN + B64_SECKEY_LEN + LINEFEED_LEN + \
KEYS_FIELD_TIME_LEN + TIME_LEN + LINEFEED_LEN \ KEYS_FIELD_TIME_LEN + TIME_LEN + LINEFEED_LEN \
@ -206,8 +200,10 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
len = strlen(p); len = strlen(p);
switch (keyt) { switch (keyt) {
case HOST: case HOST:
if (len != ONION_LEN || base32_valid(p,&cnt) || cnt != BASE32_TO_LEN(PUBONION_LEN) || if (len != ONION_LEN ||
strcmp(&p[cnt],&hostname_example[cnt]) != 0) base32_valid(p,&cnt) ||
cnt != BASE32_TO_LEN(PUBONION_LEN) ||
strcmp(&p[cnt],".onion") != 0)
{ {
fprintf(stderr,"ERROR: invalid hostname syntax\n"); fprintf(stderr,"ERROR: invalid hostname syntax\n");
return 1; return 1;