Skip to content

Commit

Permalink
Use catClientInfoStringGeneric instead of bugReportStart
Browse files Browse the repository at this point in the history
pass hide_user_info = true, only in cases where client command was
called during crash report
  • Loading branch information
naglera committed Feb 2, 2023
1 parent 760b662 commit e17ae03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
8 changes: 2 additions & 6 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,6 @@ void computeDatasetDigest(unsigned char *final) {
}
}

int isBugReportStart() {
return bug_report_start == 1;
}

#ifdef USE_JEMALLOC
void mallctl_int(client *c, robj **argv, int argc) {
int ret;
Expand Down Expand Up @@ -1796,7 +1792,7 @@ void logServerInfo(void) {
}
serverLogRaw(LL_WARNING|LL_RAW, infostring);
serverLogRaw(LL_WARNING|LL_RAW, "\n------ CLIENT LIST OUTPUT ------\n");
clients = getAllClientsInfoString(-1);
clients = getAllClientsInfoString(-1, server.hide_client_info);
serverLogRaw(LL_WARNING|LL_RAW, clients);
sdsfree(infostring);
sdsfree(clients);
Expand Down Expand Up @@ -1832,7 +1828,7 @@ void logCurrentClient(void) {
int j;

serverLogRaw(LL_WARNING|LL_RAW, "\n------ CURRENT CLIENT INFO ------\n");
client = catClientInfoString(sdsempty(),cc);
client = catClientInfoStringGeneric(sdsempty(),cc,server.hide_client_info);
serverLog(LL_WARNING|LL_RAW,"%s\n", client);
sdsfree(client);
for (j = 0; j < clientArgsToShow(cc); j++) {
Expand Down
21 changes: 10 additions & 11 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -2710,15 +2710,9 @@ char *getClientSockname(client *c) {
return c->sockname;
}

int shouldHideClientInfo() {
if (!server.hide_client_info)
return 0;
return isBugReportStart();
}

/* Concatenate a string representing the state of a client in a human
* readable format, into the sds string 's'. */
sds catClientInfoString(sds s, client *client) {
sds catClientInfoStringGeneric(sds s, client *client, bool hide_user_info) {
char flags[16], events[3], conninfo[CONN_INFO_LEN], *p;

p = flags;
Expand Down Expand Up @@ -2768,7 +2762,7 @@ sds catClientInfoString(sds s, client *client) {
getClientPeerId(client),
getClientSockname(client),
connGetInfo(client->conn, conninfo, sizeof(conninfo)),
(client->name && !shouldHideClientInfo()) ? (char*)client->name->ptr : "",
(client->name && !hide_user_info) ? (char*)client->name->ptr : "",
(long long)(server.unixtime - client->ctime),
(long long)(server.unixtime - client->lastinteraction),
flags,
Expand All @@ -2795,7 +2789,12 @@ sds catClientInfoString(sds s, client *client) {
return ret;
}

sds getAllClientsInfoString(int type) {
/* A wrapper around catClientInfoStringGeneric for regular client list usages */
sds catClientInfoString(sds s, client *client) {
return catClientInfoStringGeneric(s, client, 0);
}

sds getAllClientsInfoString(int type, bool hide_user_info) {
listNode *ln;
listIter li;
client *client;
Expand All @@ -2805,7 +2804,7 @@ sds getAllClientsInfoString(int type) {
while ((ln = listNext(&li)) != NULL) {
client = listNodeValue(ln);
if (type != -1 && getClientType(client) != type) continue;
o = catClientInfoString(o,client);
o = catClientInfoStringGeneric(o,client,hide_user_info);
o = sdscatlen(o,"\n",1);
}
return o;
Expand Down Expand Up @@ -2977,7 +2976,7 @@ NULL
}

if (!o)
o = getAllClientsInfoString(type);
o = getAllClientsInfoString(type, 0);
addReplyVerbatim(c,o,sdslen(o),"txt");
sdsfree(o);
} else if (!strcasecmp(c->argv[1]->ptr,"reply") && c->argc == 3) {
Expand Down
4 changes: 2 additions & 2 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,6 @@ extern dictType dbExpiresDictType;
extern dictType modulesDictType;
extern dictType sdsReplyDictType;
extern dict *modules;
extern int isBugReportStart();

/*-----------------------------------------------------------------------------
* Functions prototypes
Expand Down Expand Up @@ -2536,7 +2535,8 @@ void *dupClientReplyValue(void *o);
char *getClientPeerId(client *client);
char *getClientSockName(client *client);
sds catClientInfoString(sds s, client *client);
sds getAllClientsInfoString(int type);
sds catClientInfoStringGeneric(sds s, client *client, bool hide_user_info);
sds getAllClientsInfoString(int type, bool hide_user_info);
int clientSetName(client *c, robj *name);
void rewriteClientCommandVector(client *c, int argc, ...);
void rewriteClientCommandArgument(client *c, int i, robj *newval);
Expand Down

0 comments on commit e17ae03

Please sign in to comment.