Date: Wed, 9 Aug 2006 17:16:58 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 103515 for review Message-ID: <200608091716.k79HGw9Y080596@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=103515 Change 103515 by bushman@bushman_nss_ldap_cached on 2006/08/09 17:16:25 Some memory errors handling issues fixed. Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nscache.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nscachedcli.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nsdispatch.c#6 edit Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nscache.c#2 (text) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> + * Copyright (c) 2005 Michael Bushkov <bushman@freebsd.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -71,6 +71,10 @@ params.socket_path = CACHED_SOCKET_PATH; cache_data->key = (char *)malloc(NSS_CACHE_KEY_INITIAL_SIZE); + if (cache_data->key == NULL) { + cache_data->key_size = 0; + return (NS_UNAVAIL); + } memset(cache_data->key, 0, NSS_CACHE_KEY_INITIAL_SIZE); cache_data->key_size = NSS_CACHE_KEY_INITIAL_SIZE; va_copy(ap_new, ap); @@ -85,8 +89,12 @@ break; cache_data->key_size <<= 1; - cache_data->key = realloc(cache_data->key, + cache_data->key = reallocf(cache_data->key, cache_data->key_size); + if (cache_data->key == NULL) { + res = NS_UNAVAIL; + break; + } memset(cache_data->key, 0, cache_data->key_size); va_copy(ap_new, ap); } @@ -102,6 +110,8 @@ buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + if (buffer == NULL) + return (NS_UNAVAIL); memset(buffer, 0, NSS_CACHE_BUFFER_INITIAL_SIZE); do { @@ -115,7 +125,9 @@ &buffer_size); __close_cached_connection(connection); if (res == -2 && buffer_size < NSS_CACHE_BUFFER_SIZE_LIMIT) { - buffer = (char *)realloc(buffer, buffer_size); + buffer = (char *)reallocf(buffer, buffer_size); + if (buffer == NULL) + return (NS_UNAVAIL); memset(buffer, 0, buffer_size); } } while (res == -2); @@ -185,6 +197,11 @@ buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + if (buffer == NULL) { + __close_cached_connection(connection); + free(cache_data->key); + return (NS_UNAVAIL); + } memset(buffer, 0, NSS_CACHE_BUFFER_INITIAL_SIZE); do { @@ -201,7 +218,11 @@ break; buffer_size <<= 1; - buffer = (char *)realloc(buffer, buffer_size); + buffer = (char *)reallocf(buffer, buffer_size); + if (buffer == NULL) { + res = NS_UNAVAIL; + break; + } memset(buffer, 0, buffer_size); } } while (res == NS_RETURN); @@ -291,12 +312,22 @@ buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + if (buffer == NULL) { + __close_cached_mp_read_session(rs); + rs = INVALID_CACHED_MP_READ_SESSION; + cache_info->set_mp_rs_func(rs); + return (NS_UNAVAIL); + } memset(buffer, 0, NSS_CACHE_BUFFER_INITIAL_SIZE); do { res = __cached_mp_read(rs, buffer, &buffer_size); if (res == -2 && buffer_size < NSS_CACHE_BUFFER_SIZE_LIMIT) { - buffer = (char *)realloc(buffer, buffer_size); + buffer = (char *)reallocf(buffer, buffer_size); + if (buffer == NULL) { + res = -1; + break; + } memset(buffer, 0, buffer_size); } } while (res == -2); @@ -341,6 +372,12 @@ cache_data = (nss_cache_data *)mdata; cache_info = cache_data->info; + buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; + buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + if (buffer == NULL) + return (NS_UNAVAIL); + memset(buffer, 0, NSS_CACHE_BUFFER_INITIAL_SIZE); + ws = cache_info->get_mp_ws_func(); if (ws == INVALID_CACHED_MP_WRITE_SESSION) { memset(¶ms, 0, sizeof(struct cached_connection_params)); @@ -354,10 +391,6 @@ cache_info->set_mp_ws_func(ws); } - buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; - buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); - memset(buffer, 0, NSS_CACHE_BUFFER_INITIAL_SIZE); - do { size_t size; @@ -372,7 +405,11 @@ break; buffer_size <<= 1; - buffer = (char *)realloc(buffer, buffer_size); + buffer = (char *)reallocf(buffer, buffer_size); + if (buffer == NULL) { + res = NS_UNAVAIL; + break; + } memset(buffer, 0, buffer_size); } } while (res == NS_RETURN); ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nscachedcli.c#2 (text) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> + * Copyright (c) 2005 Michael Bushkov <bushman@freebsd.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -215,19 +215,31 @@ _fcntl(client_socket, F_SETFL, O_NONBLOCK); retval = malloc(sizeof(struct cached_connection_)); - assert(retval != NULL); + if (retval == NULL) { + _close(client_socket); + return (NULL); + } memset(retval, 0, sizeof(struct cached_connection_)); retval->sockfd = client_socket; retval->write_queue = kqueue(); - assert(retval->write_queue != -1); + if (retval->write_queue == -1) { + _close(client_socket); + free(retval); + return (NULL); + } EV_SET(&eventlist, retval->sockfd, EVFILT_WRITE, EV_ADD, 0, 0, NULL); res = kevent(retval->write_queue, &eventlist, 1, NULL, 0, NULL); retval->read_queue = kqueue(); - assert(retval->read_queue != -1); + if (retval->read_queue == -1) { + _close(client_socket); + _close(retval->write_queue); + free(retval); + return (NULL); + } EV_SET(&eventlist, retval->sockfd, EVFILT_READ, EV_ADD, 0, 0, NULL); res = kevent(retval->read_queue, &eventlist, 1, NULL, 0, NULL); ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nsdispatch.c#6 (text+ko) ==== @@ -707,7 +707,8 @@ __nss_common_cache_write_negative(cache_data_p); } va_end(ap); - } + } else if (cache_data_p != NULL) + free(cache_data.key); #endif /* NS_CACHING */ if (isthreaded)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608091716.k79HGw9Y080596>