Skip to content

Commit 8c1c36b

Browse files
author
Aakanksha Verma
committed
Bug#21288106 - MISSING SANITY CHECK FOR STRDUP() IN HTTP.C PLUS POTENTIAL PROBLEM
Sanity checks were missing in memcached code after memory allocations. FIX Put proper checks after memory alloction.MEMORY LEAK. * Reviewed by :Jimmy RB :10036
1 parent 69d4e72 commit 8c1c36b

5 files changed

Lines changed: 78 additions & 5 deletions

File tree

libevent/http.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (c) 2002-2006 Niels Provos <[email protected]>
33
* All rights reserved.
4+
* This file was modified by Oracle on 28-08-2015.
5+
* Modifications copyright (c) 2015, Oracle and/or its affiliates.
6+
* All rights reserved.
47
*
58
* Redistribution and use in source and binary forms, with or without
69
* modification, are permitted provided that the following conditions
@@ -105,6 +108,7 @@
105108

106109
#define NI_NUMERICHOST 1
107110
#define NI_NUMERICSERV 2
111+
#define INNODB_CHANGED
108112

109113
static int
110114
fake_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
@@ -2400,6 +2404,14 @@ evhttp_set_cb(struct evhttp *http, const char *uri,
24002404
event_err(1, "%s: calloc", __func__);
24012405

24022406
http_cb->what = strdup(uri);
2407+
2408+
#ifdef INNODB_CHANGED
2409+
if (http_cb->what == NULL) {
2410+
free(http_cb);
2411+
event_err(1, "%s: strdup",__func__);
2412+
}
2413+
#endif
2414+
24032415
http_cb->cb = cb;
24042416
http_cb->cbarg = cbarg;
24052417

libevent/test/regress_http.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (c) 2003-2006 Niels Provos <[email protected]>
33
* All rights reserved.
4+
* This file was modified by Oracle on 28-08-2015.
5+
* Modifications copyright (c) 2015, Oracle and/or its affiliates.
6+
* All rights reserved.
47
*
58
* Redistribution and use in source and binary forms, with or without
69
* modification, are permitted provided that the following conditions
@@ -57,6 +60,8 @@
5760
#include "log.h"
5861
#include "http-internal.h"
5962

63+
#define INNODB_CHANGED
64+
6065
extern int pair[];
6166
extern int test_ok;
6267

@@ -278,6 +283,15 @@ http_chunked_cb(struct evhttp_request *req, void *arg)
278283
{
279284
struct timeval when = { 0, 0 };
280285
struct chunk_req_state *state = malloc(sizeof(struct chunk_req_state));
286+
287+
#ifdef INNODB_CHANGED
288+
if (!state) {
289+
fprintf(stderr, "Unable to allocate memory in"
290+
"http_chunked_cb...\n");
291+
exit (1);
292+
}
293+
#endif
294+
281295
event_debug(("%s: called\n", __func__));
282296

283297
memset(state, 0, sizeof(struct chunk_req_state));

plugin/innodb_memcached/daemon_memcached/daemon/memcached.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* http://www.danga.com/memcached/
66
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
77
* Copyright 2003 Danga Interactive, Inc. All rights reserved.
8+
* This file was modified by Oracle on 28-08-2015.
9+
* Modifications copyright (c) 2015, Oracle and/or its affiliates.
10+
* All rights reserved.
811
*
912
* Use and distribution licensed under the BSD license. See
1013
* the LICENSE file for full text.
@@ -6430,6 +6433,15 @@ static void *new_independent_stats(void) {
64306433
int ii;
64316434
int nrecords = num_independent_stats();
64326435
struct independent_stats *independent_stats = calloc(sizeof(independent_stats) + sizeof(struct thread_stats) * nrecords, 1);
6436+
6437+
#ifdef INNODB_MEMCACHED
6438+
if (independent_stats == NULL) {
6439+
fprintf(stderr, "Unable to allocate memory for"
6440+
"independent_stats...\n");
6441+
return (NULL);
6442+
}
6443+
#endif
6444+
64336445
if (settings.topkeys > 0)
64346446
independent_stats->topkeys = topkeys_init(settings.topkeys);
64356447
for (ii = 0; ii < nrecords; ii++)
@@ -7858,6 +7870,12 @@ int main (int argc, char **argv) {
78587870

78597871
default_independent_stats = new_independent_stats();
78607872

7873+
#ifdef INNODB_MEMCACHED
7874+
if (!default_independent_stats) {
7875+
exit(EXIT_FAILURE);
7876+
}
7877+
#endif
7878+
78617879
#ifndef __WIN32__
78627880
/*
78637881
* ignore SIGPIPE signals; we can use errno == EPIPE if we

plugin/innodb_memcached/innodb_memcache/src/innodb_api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,11 @@ innodb_api_fill_value(
731731
if (col_id == col_info[CONTAINER_VALUE].field_id) {
732732

733733
if (alloc_mem) {
734+
735+
/* when using innodb memcache the
736+
code will never come here becasue
737+
we do not allocate memory for column
738+
objects */
734739
innodb_api_copy_mci(
735740
read_tpl, col_id,
736741
&item->col_value[MCI_COL_VALUE]);

plugin/innodb_memcached/innodb_memcache/src/innodb_engine.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ create_instance(
169169
}
170170

171171
innodb_eng = malloc(sizeof(struct innodb_engine));
172-
memset(innodb_eng, 0, sizeof(*innodb_eng));
173172

174173
if (innodb_eng == NULL) {
175174
return(ENGINE_ENOMEM);
176175
}
177176

177+
memset(innodb_eng, 0, sizeof(*innodb_eng));
178178
innodb_eng->engine.interface.interface = 1;
179179
innodb_eng->engine.get_info = innodb_get_info;
180180
innodb_eng->engine.initialize = innodb_initialize;
@@ -887,21 +887,45 @@ innodb_conn_init(
887887

888888
memset(conn_data, 0, sizeof(*conn_data));
889889
conn_data->result = malloc(sizeof(mci_item_t));
890-
conn_data->conn_cookie = (void*) cookie;
891-
UT_LIST_ADD_LAST(conn_list, engine->conn_data, conn_data);
892-
engine->server.cookie->store_engine_specific(
893-
cookie, conn_data);
890+
if (!conn_data->result) {
891+
UNLOCK_CONN_IF_NOT_LOCKED(has_lock, engine);
892+
free(conn_data);
893+
conn_data = NULL;
894+
return(NULL);
895+
}
894896
conn_data->conn_meta = new_meta_info
895897
? new_meta_info
896898
: engine->meta_info;
897899
conn_data->row_buf = malloc(1024);
900+
if (!conn_data->row_buf) {
901+
UNLOCK_CONN_IF_NOT_LOCKED(has_lock, engine);
902+
free(conn_data->result);
903+
free(conn_data);
904+
conn_data = NULL;
905+
return(NULL);
906+
}
898907
conn_data->row_buf_len = 1024;
899908

900909
conn_data->cmd_buf = malloc(1024);
910+
if (!conn_data->cmd_buf) {
911+
UNLOCK_CONN_IF_NOT_LOCKED(has_lock, engine);
912+
free(conn_data->row_buf);
913+
free(conn_data->result);
914+
free(conn_data);
915+
conn_data = NULL;
916+
return(NULL);
917+
}
901918
conn_data->cmd_buf_len = 1024;
902919

903920
conn_data->is_flushing = false;
904921

922+
conn_data->conn_cookie = (void*) cookie;
923+
924+
/* Add connection to the list after all memory allocations */
925+
UT_LIST_ADD_LAST(conn_list, engine->conn_data, conn_data);
926+
engine->server.cookie->store_engine_specific(
927+
cookie, conn_data);
928+
905929
pthread_mutex_init(&conn_data->curr_conn_mutex, NULL);
906930
UNLOCK_CONN_IF_NOT_LOCKED(has_lock, engine);
907931
}

0 commit comments

Comments
 (0)