aboutsummaryrefslogtreecommitdiffstats
path: root/key2root-addkey.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-06-23 16:24:26 +0200
committerMattias Andrée <maandree@kth.se>2023-06-23 16:24:26 +0200
commit2a717740fa534a3a5bd0040ef9606e15bbe7115c (patch)
treee78cd57b48a31c9178d12cac53d0f40a957becf3 /key2root-addkey.c
parentImplement authentication (diff)
downloadkey2root-2a717740fa534a3a5bd0040ef9606e15bbe7115c.tar.gz
key2root-2a717740fa534a3a5bd0040ef9606e15bbe7115c.tar.bz2
key2root-2a717740fa534a3a5bd0040ef9606e15bbe7115c.tar.xz
Fix mistakes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--key2root-addkey.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/key2root-addkey.c b/key2root-addkey.c
index 78435f3..989aa8f 100644
--- a/key2root-addkey.c
+++ b/key2root-addkey.c
@@ -48,7 +48,7 @@ checkkey(char *data, size_t whead, size_t *rheadp, size_t *rhead2p, size_t *line
int failed = 0;
size_t len;
- while (*rhead2p < whead || data[*rhead2p] != '\n')
+ while (*rhead2p < whead && data[*rhead2p] != '\n')
++*rhead2p;
if (data[*rhead2p] != '\n')
@@ -66,7 +66,7 @@ checkkey(char *data, size_t whead, size_t *rheadp, size_t *rhead2p, size_t *line
failed = 1;
}
- if (failed || klen >= len || data[*rheadp + klen] != ' ' || memcpy(&data[*rheadp], keyname, klen)) {
+ if (failed || klen >= len || data[*rheadp + klen] != ' ' || memcmp(&data[*rheadp], keyname, klen)) {
*rheadp = ++*rhead2p;
return 0;
} else {
@@ -196,10 +196,8 @@ main(int argc, char *argv[])
if (failed)
return 1;
- if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
+ if (mlockall(MCL_CURRENT | MCL_FUTURE))
fprintf(stderr, "%s: mlockall MCL_CURRENT|MCL_FUTURE: %s\n", argv0, strerror(errno));
- exit(1);
- }
if (!parameters) {
stpcpy(mksalt(stpcpy(generated_parameters, HASH_PREFIX)), "$");
@@ -238,8 +236,8 @@ main(int argc, char *argv[])
fprintf(stderr, "%s: crypt <key> %s: %s\n", argv0, parameters, strerror(errno));
explicit_bzero(key, key_len);
free(key);
- key_size = key_len = strlen(keyname) + strlen(hash) + 3;
- key = malloc(key_len);
+ key_size = key_len = strlen(keyname) + strlen(hash) + 2;
+ key = malloc(key_len + 1);
if (!key) {
fprintf(stderr, "%s: malloc: %s\n", argv0, strerror(errno));
exit(1);
@@ -284,7 +282,7 @@ main(int argc, char *argv[])
gap_size = end - beginning;
if (gap_size > key_len) {
memmove(&data[beginning + key_len], &data[end], data_len - end);
- data_len -= key_len - gap_size;
+ data_len -= gap_size - key_len;
} else if (gap_size < key_len) {
gap_increase = key_len - gap_size;
if (data_len + gap_increase > data_size) {
@@ -295,7 +293,7 @@ main(int argc, char *argv[])
exit(1);
}
}
- memmove(&data[end], &data[end + gap_increase], data_len - end);
+ memmove(&data[end + gap_increase], &data[end], data_len - end);
data_len += gap_increase;
}
memcpy(&data[beginning], key, key_len);