aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-01-15 10:05:59 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-01-26 13:56:22 +0100
commit89f58decb6e0ecadb37ab77c471ec780203fcd17 (patch)
tree706a137c3857e3ee9ea9a05943de7a42b7b73312 /src
parent5ed5e97114bfe83473f398056653e7149cc285dd (diff)
downloadlibssh-89f58decb6e0ecadb37ab77c471ec780203fcd17.tar.gz
libssh-89f58decb6e0ecadb37ab77c471ec780203fcd17.tar.xz
libssh-89f58decb6e0ecadb37ab77c471ec780203fcd17.zip
misc: Add NULL checks before accessing lists
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/misc.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/misc.c b/src/misc.c
index abb82425..070a7766 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -485,9 +485,17 @@ static struct ssh_iterator *ssh_iterator_new(const void *data){
}
int ssh_list_append(struct ssh_list *list,const void *data){
- struct ssh_iterator *iterator=ssh_iterator_new(data);
- if(!iterator)
- return SSH_ERROR;
+ struct ssh_iterator *iterator = NULL;
+
+ if (list == NULL) {
+ return SSH_ERROR;
+ }
+
+ iterator = ssh_iterator_new(data);
+ if (iterator == NULL) {
+ return SSH_ERROR;
+ }
+
if(!list->end){
/* list is empty */
list->root=list->end=iterator;
@@ -500,8 +508,13 @@ int ssh_list_append(struct ssh_list *list,const void *data){
}
int ssh_list_prepend(struct ssh_list *list, const void *data){
- struct ssh_iterator *it = ssh_iterator_new(data);
+ struct ssh_iterator *it = NULL;
+ if (list == NULL) {
+ return SSH_ERROR;
+ }
+
+ it = ssh_iterator_new(data);
if (it == NULL) {
return SSH_ERROR;
}
@@ -520,6 +533,11 @@ int ssh_list_prepend(struct ssh_list *list, const void *data){
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator){
struct ssh_iterator *ptr,*prev;
+
+ if (list == NULL) {
+ return;
+ }
+
prev=NULL;
ptr=list->root;
while(ptr && ptr != iterator){
@@ -554,10 +572,17 @@ void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator){
* if the list is empty.
*/
const void *_ssh_list_pop_head(struct ssh_list *list){
- struct ssh_iterator *iterator=list->root;
- const void *data;
- if(!list->root)
- return NULL;
+ struct ssh_iterator *iterator = NULL;
+ const void *data = NULL;
+
+ if (list == NULL) {
+ return NULL;
+ }
+
+ iterator = list->root;
+ if (iterator == NULL) {
+ return NULL;
+ }
data=iterator->data;
list->root=iterator->next;
if(list->end==iterator)