-
Notifications
You must be signed in to change notification settings - Fork 238
[WIP] Introduce __conn_id__ placeholder #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,9 @@ class client : public connections_manager { | |
| // test related | ||
| benchmark_config* m_config; | ||
| object_generator* m_obj_gen; | ||
| std::string m_conn_id_str; | ||
| const char* m_conn_id_value; | ||
| unsigned int m_conn_id_value_len; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused member variable
|
||
| run_stats m_stats; | ||
|
|
||
| unsigned long long m_reqs_processed; // requests processed (responses received) | ||
|
|
@@ -78,13 +81,14 @@ class client : public connections_manager { | |
| keylist *m_keylist; // used to construct multi commands | ||
|
|
||
| public: | ||
| client(client_group* group); | ||
| client(struct event_base *event_base, benchmark_config *config, abstract_protocol *protocol, object_generator *obj_gen); | ||
| client(client_group* group, unsigned int conn_id = 0); | ||
| client(struct event_base *event_base, benchmark_config *config, abstract_protocol *protocol, object_generator *obj_gen, unsigned int conn_id = 0); | ||
| virtual ~client(); | ||
| bool setup_client(benchmark_config *config, abstract_protocol *protocol, object_generator *obj_gen); | ||
| int prepare(void); | ||
| bool initialized(void); | ||
| run_stats* get_stats(void) { return &m_stats; } | ||
| const char* get_conn_id_value(void) { return m_conn_id_value; } | ||
|
|
||
| virtual get_key_response get_key_for_conn(unsigned int command_index, unsigned int conn_id, unsigned long long* key_index); | ||
| virtual bool create_arbitrary_request(unsigned int command_index, struct timeval& timestamp, unsigned int conn_id); | ||
|
|
@@ -203,8 +207,10 @@ class client_group { | |
| abstract_protocol* m_protocol; | ||
| object_generator* m_obj_gen; | ||
| std::vector<client*> m_clients; | ||
| protected: | ||
| unsigned int m_thread_id; | ||
| public: | ||
| client_group(benchmark_config *cfg, abstract_protocol *protocol, object_generator* obj_gen); | ||
| client_group(benchmark_config *cfg, abstract_protocol *protocol, object_generator* obj_gen, unsigned int thread_id); | ||
| ~client_group(); | ||
|
|
||
| int create_clients(int count); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #include <assert.h> | ||
| /* | ||
| * Copyright (C) 2011-2017 Redis Labs Ltd. | ||
| * | ||
|
|
@@ -175,7 +176,7 @@ class redis_protocol : public abstract_protocol { | |
| redis_protocol() : m_response_state(rs_initial), m_bulk_len(0), m_response_len(0), m_total_bulks_count(0), m_current_mbulk(NULL), m_resp3(false), m_attribute(false) { } | ||
| virtual redis_protocol* clone(void) { return new redis_protocol(); } | ||
| virtual int select_db(int db); | ||
| virtual int authenticate(const char *credentials); | ||
| virtual int authenticate(const char *user, const char *credentials); | ||
| virtual int configure_protocol(enum PROTOCOL_TYPE type); | ||
| virtual int write_command_cluster_slots(); | ||
| virtual int write_command_set(const char *key, int key_len, const char *value, int value_len, int expiry, unsigned int offset); | ||
|
|
@@ -206,7 +207,7 @@ int redis_protocol::select_db(int db) | |
| return size; | ||
| } | ||
|
|
||
| int redis_protocol::authenticate(const char *credentials) | ||
| int redis_protocol::authenticate(const char *user, const char *credentials) | ||
| { | ||
| int size = 0; | ||
| assert(credentials != NULL); | ||
|
|
@@ -219,7 +220,6 @@ int redis_protocol::authenticate(const char *credentials) | |
| * contains a colon. | ||
| */ | ||
|
|
||
| const char *user = NULL; | ||
| const char *password; | ||
|
|
||
| if (credentials[0] == ':') { | ||
|
|
@@ -229,12 +229,11 @@ int redis_protocol::authenticate(const char *credentials) | |
| if (!password) { | ||
| password = credentials; | ||
| } else { | ||
| user = credentials; | ||
| password++; | ||
| } | ||
| } | ||
|
|
||
| if (!user) { | ||
| if (!user || strlen(user) == 0) { | ||
| size = evbuffer_add_printf(m_write_buf, | ||
| "*2\r\n" | ||
| "$4\r\n" | ||
|
|
@@ -243,17 +242,16 @@ int redis_protocol::authenticate(const char *credentials) | |
| "%s\r\n", | ||
| strlen(password), password); | ||
| } else { | ||
| size_t user_len = password - user - 1; | ||
| size_t user_len = strlen(user); | ||
| size = evbuffer_add_printf(m_write_buf, | ||
| "*3\r\n" | ||
| "$4\r\n" | ||
| "AUTH\r\n" | ||
| "$%zu\r\n" | ||
| "%.*s\r\n" | ||
| "%s\r\n" | ||
| "$%zu\r\n" | ||
| "%s\r\n", | ||
| user_len, | ||
| (int) user_len, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Authentication silently ignores configured username from credentialsHigh Severity When users configure authentication with Additional Locations (1) |
||
| user, | ||
| strlen(password), | ||
| password); | ||
|
|
@@ -723,8 +721,10 @@ bool redis_protocol::format_arbitrary_command(arbitrary_command &cmd) { | |
| benchmark_error_log("error: data placeholder can't combined with other data\n"); | ||
| return false; | ||
| } | ||
|
|
||
| current_arg->type = data_type; | ||
| } else if (current_arg->data.find(CONN_PLACEHOLDER) != std::string::npos) { | ||
| // Allow conn_id placeholder to be combined with other text | ||
| current_arg->type = conn_id_type; | ||
| } | ||
|
|
||
| // we expect that first arg is the COMMAND name | ||
|
|
@@ -761,7 +761,7 @@ class memcache_text_protocol : public abstract_protocol { | |
| memcache_text_protocol() : m_response_state(rs_initial), m_value_len(0), m_response_len(0) { } | ||
| virtual memcache_text_protocol* clone(void) { return new memcache_text_protocol(); } | ||
| virtual int select_db(int db); | ||
| virtual int authenticate(const char *credentials); | ||
| virtual int authenticate(const char *user, const char *credentials); | ||
| virtual int configure_protocol(enum PROTOCOL_TYPE type); | ||
| virtual int write_command_cluster_slots(); | ||
| virtual int write_command_set(const char *key, int key_len, const char *value, int value_len, int expiry, unsigned int offset); | ||
|
|
@@ -782,7 +782,7 @@ int memcache_text_protocol::select_db(int db) | |
| assert(0); | ||
| } | ||
|
|
||
| int memcache_text_protocol::authenticate(const char *credentials) | ||
| int memcache_text_protocol::authenticate(const char *user, const char *credentials) | ||
| { | ||
| assert(0); | ||
| } | ||
|
|
@@ -983,7 +983,7 @@ class memcache_binary_protocol : public abstract_protocol { | |
| memcache_binary_protocol() : m_response_state(rs_initial), m_response_len(0) { } | ||
| virtual memcache_binary_protocol* clone(void) { return new memcache_binary_protocol(); } | ||
| virtual int select_db(int db); | ||
| virtual int authenticate(const char *credentials); | ||
| virtual int authenticate(const char *user, const char *credentials); | ||
| virtual int configure_protocol(enum PROTOCOL_TYPE type); | ||
| virtual int write_command_cluster_slots(); | ||
| virtual int write_command_set(const char *key, int key_len, const char *value, int value_len, int expiry, unsigned int offset); | ||
|
|
@@ -1003,14 +1003,13 @@ int memcache_binary_protocol::select_db(int db) | |
| assert(0); | ||
| } | ||
|
|
||
| int memcache_binary_protocol::authenticate(const char *credentials) | ||
| int memcache_binary_protocol::authenticate(const char *user, const char *credentials) | ||
| { | ||
| protocol_binary_request_no_extras req; | ||
| char nullbyte = '\0'; | ||
| const char mechanism[] = "PLAIN"; | ||
| int mechanism_len = sizeof(mechanism) - 1; | ||
| const char *colon; | ||
| const char *user; | ||
| int user_len; | ||
| const char *passwd; | ||
| int passwd_len; | ||
|
|
@@ -1019,8 +1018,8 @@ int memcache_binary_protocol::authenticate(const char *credentials) | |
| colon = strchr(credentials, ':'); | ||
| assert(colon != NULL); | ||
|
|
||
| user = credentials; | ||
| user_len = colon - user; | ||
| // Use the user parameter instead of extracting from credentials | ||
| user_len = strlen(user); | ||
| passwd = colon + 1; | ||
| passwd_len = strlen(passwd); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent conn_id string format between constructors
Medium Severity
The two
clientconstructors initializem_conn_id_strwith different formats. The constructor takingclient_group*(line 118) uses"user" + std::to_string(conn_id)producing strings like "user1", while the constructor takingevent_base*(line 141) uses juststd::to_string(conn_id)producing strings like "1". This causes the__conn_id__placeholder to produce inconsistent values depending on which code path creates the client (e.g.,verify_clientuses the second constructor).Additional Locations (1)
client.cpp#L117-L118