Skip to content

Commit

Permalink
Fix potential race condition
Browse files Browse the repository at this point in the history
Guard the modification of "entry_counter" and the read
used to decide whether to modify "entry_counter" with the
same set of locks

Resolves: #478

Signed-off-by: Sergio Arroutbi <[email protected]>
  • Loading branch information
sarroutbi authored and sergio-correia committed Oct 7, 2024
1 parent 7ed0e26 commit 17a2063
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pins/pkcs11/clevis-pkcs11-afunix-socket-unlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,23 @@ get_control_socket_name(const char* file_sock, char* control_sock, uint32_t cont
}

static void insert_device(const char* dev) {
pthread_mutex_lock(&mutex);
if(MAX_ENTRIES == entry_counter) {
pthread_mutex_unlock(&mutex);
perror("No more entries accepted\n");
return;
}
pthread_mutex_lock(&mutex);
strncpy(keys[entry_counter].dev, dev, MAX_DEVICE);
pthread_mutex_unlock(&mutex);
}

static void insert_key(const char* key) {
pthread_mutex_lock(&mutex);
if(MAX_ENTRIES == entry_counter) {
pthread_mutex_unlock(&mutex);
perror("No more entries accepted\n");
return;
}
pthread_mutex_lock(&mutex);
strncpy(keys[entry_counter++].key, key, MAX_KEY);
pthread_mutex_unlock(&mutex);
}
Expand Down

0 comments on commit 17a2063

Please sign in to comment.