Skip to content

Commit

Permalink
Disallow control characters in mosquitto_passwd usernames.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Jan 6, 2021
1 parent 93c730f commit 70db9c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Broker:
/var/lib/mosquitto/mosquitto.db.new. Closes #1978.
- Fix potential intermittent initial bridge connections when using poll().

Apps:
- Disallow control characters in mosquitto_passwd usernames.


2.0.4 - 2020-12-22
==================
Expand Down
38 changes: 29 additions & 9 deletions apps/mosquitto_passwd/mosquitto_passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SPDX-License-Identifier: EPL-2.0 OR EDL-1.0

#include "config.h"

#include <ctype.h>
#include <errno.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
Expand Down Expand Up @@ -378,6 +379,32 @@ void handle_sigint(int signal)
exit(0);
}


static bool is_username_valid(const char *username)
{
int i;
size_t slen;

if(username){
slen = strlen(username);
if(slen > 65535){
fprintf(stderr, "Error: Username must be less than 65536 characters long.\n");
return false;
}
for(i=0; i<slen; i++){
if(iscntrl(username[i])){
fprintf(stderr, "Error: Username must not contain control characters.\n");
return false;
}
}
if(strchr(username, ':')){
fprintf(stderr, "Error: Username must not contain the ':' character.\n");
return false;
}
}
return true;
}

int main(int argc, char *argv[])
{
char *password_file_tmp = NULL;
Expand Down Expand Up @@ -514,15 +541,8 @@ int main(int argc, char *argv[])
return 1;
}

if(username){
if(strlen(username) > 65535){
fprintf(stderr, "Error: Username must be less than 65536 characters long.\n");
return 1;
}
if(strchr(username, ':')){
fprintf(stderr, "Error: Username must not contain the ':' character.\n");
return 1;
}
if(!is_username_valid(username)){
return 1;
}
if(password_cmd && strlen(password_cmd) > 65535){
fprintf(stderr, "Error: Password must be less than 65536 characters long.\n");
Expand Down

0 comments on commit 70db9c4

Please sign in to comment.