Skip to content

Commit b4645c4

Browse files
committed
fix(delagent): repair generation of hash for authentication
* The function `SHA1(...)` could generate strings containing `\000` which did not work with the following call of `strlen(...)` * This is solved, since one knows that a SHA1 hash as hex is 40 characters long (20 chars for the raw value) * The old test, whether the creation of the sha1 failed, can not work since the first char could also be `\000` ==> removed
1 parent b1313ae commit b4645c4

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/delagent/agent/util.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ int authentication(char *user, char *password, int *user_id, int *user_perm)
9595
char SQL[MAXSQL] = {0};
9696
PGresult *result;
9797
char user_seed[myBUFSIZ] = {0};
98-
char pass_hash_valid[myBUFSIZ] = {0};
99-
unsigned char hash_value[myBUFSIZ] = {0};
100-
char pass_hash_actual[myBUFSIZ] = {0};
98+
char pass_hash_valid[41] = {0};
99+
unsigned char pass_hash_actual_raw[21] = {0};
100+
char pass_hash_actual[41] = {0};
101101

102102
/** get user_seed, user_pass on one specified user */
103103
snprintf(SQL,MAXSQL,"SELECT user_seed, user_pass, user_perm, user_pk from users where user_name='%s';", user);
@@ -118,22 +118,17 @@ int authentication(char *user, char *password, int *user_id, int *user_perm)
118118
if (user_seed[0] && pass_hash_valid[0])
119119
{
120120
strcat(user_seed, password); // get the hash code on seed+pass
121-
SHA1((unsigned char *)user_seed, strlen(user_seed), hash_value);
122-
if (!hash_value[0])
123-
{
124-
LOG_FATAL("ERROR, failed to get sha1 value\n");
125-
return -1;
126-
}
121+
SHA1((unsigned char *)user_seed, strlen(user_seed), pass_hash_actual_raw);
127122
}
128123
else
129124
{
130125
return -1;
131126
}
132127
int i = 0;
133128
char temp[256] = {0};
134-
for (i = 0; i < strlen((char *)hash_value); i++)
129+
for (i = 0; i < 20; i++)
135130
{
136-
snprintf(temp, 256, "%02x", hash_value[i]);
131+
snprintf(temp, 256, "%02x", pass_hash_actual_raw[i]);
137132
strcat(pass_hash_actual, temp);
138133
}
139134
return strcmp(pass_hash_valid, pass_hash_actual) == 0;

0 commit comments

Comments
 (0)