Skip to content

Commit 159be46

Browse files
author
aditya
committed
Bug #20478242 MEMCAHCED SET COMMAND ACCEPTS NEGATIVE VALUES FOR EXPIRE TIME
PROBLEM Inside memcached server the expire time is stored as unsigned int,so when the user gives a negative value it is converted to a large number and is accepted. FIX Simple and easy fix is to restrict the maximum value of expire time to INT_MAX32 since any negative value will be greater than this and we can reject it. Also removed useless assert in innodb_flush_sync_conn() function
1 parent 96dfb59 commit 159be46

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

plugin/innodb_memcached/daemon_memcached/daemon/memcached.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* memcached - memory caching daemon
44
*
55
* http://www.danga.com/memcached/
6-
*
6+
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
77
* Copyright 2003 Danga Interactive, Inc. All rights reserved.
88
*
99
* Use and distribution licensed under the BSD license. See
@@ -4247,6 +4247,13 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
42474247
return;
42484248
}
42494249

4250+
/* Negative expire values not allowed */
4251+
4252+
if (exptime_int < 0) {
4253+
out_string(c, "CLIENT_ERROR Invalid expire time");
4254+
return;
4255+
}
4256+
42504257
/* Ubuntu 8.04 breaks when I pass exptime to safe_strtol */
42514258
exptime = exptime_int;
42524259

plugin/innodb_memcached/daemon_memcached/utilities/util.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
13
#include "config.h"
24
#include <stdio.h>
35
#include <assert.h>
@@ -9,6 +11,8 @@
911

1012
#include "memcached/util.h"
1113

14+
15+
#define INT_MAX32 0x7fffffff
1216
/* Avoid warnings on solaris, where isspace() is an index into an array, and gcc uses signed chars */
1317
#define xisspace(c) isspace((unsigned char)c)
1418

@@ -79,6 +83,7 @@ bool safe_strtoul(const char *str, uint32_t *out) {
7983
return false;
8084
}
8185

86+
/*Function converts string into int */
8287
bool safe_strtol(const char *str, int32_t *out) {
8388
assert(out != NULL);
8489
errno = 0;
@@ -87,6 +92,10 @@ bool safe_strtol(const char *str, int32_t *out) {
8792
long l = strtol(str, &endptr, 10);
8893
if (errno == ERANGE)
8994
return false;
95+
96+
if (l > INT_MAX32)
97+
return false;
98+
9099
if (xisspace(*endptr) || (*endptr == '\0' && endptr != str)) {
91100
*out = l;
92101
return true;

plugin/innodb_memcached/innodb_memcache/src/innodb_engine.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,6 @@ innodb_flush_sync_conn(
20272027

20282028
curr_conn_data = engine->server.cookie->get_engine_specific(cookie);
20292029
assert(curr_conn_data);
2030-
assert(!engine->enable_binlog || curr_conn_data->thd);
20312030

20322031
conn_data = UT_LIST_GET_FIRST(engine->conn_data);
20332032

0 commit comments

Comments
 (0)