Blame SOURCES/tree-static-analysis.patch

257807
From 48641275c0cd018441685f2d3145038017f1ea42 Mon Sep 17 00:00:00 2001
257807
From: Kamil Dudka <kdudka@redhat.com>
257807
Date: Tue, 6 Nov 2018 16:31:32 +0100
257807
Subject: [PATCH] tree: fix programming mistakes detected by static analysis
257807
257807
---
257807
 html.c |  5 +++--
257807
 json.c | 11 +++++------
257807
 tree.c |  2 +-
257807
 unix.c |  5 +++--
257807
 xml.c  | 11 +++++------
257807
 5 files changed, 17 insertions(+), 17 deletions(-)
257807
257807
diff --git a/html.c b/html.c
257807
index 75e2ed1..35fb525 100644
257807
--- a/html.c
257807
+++ b/html.c
257807
@@ -221,7 +221,7 @@ off_t html_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 	    if (*(*dir)->lnk == '/')
257807
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
257807
 	    else {
257807
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
257807
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
257807
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
257807
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
257807
 	      listdir(path,dt,ft,lev+1,dev);
257807
@@ -254,7 +254,7 @@ off_t html_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 {
257807
   struct _info **dir;
257807
   off_t size = 0;
257807
-  char *err;
257807
+  char *err = NULL;
257807
   
257807
   dir = getfulltree(d, lev, dev, &size, &err;;
257807
   
257807
@@ -262,6 +262,7 @@ off_t html_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
   
257807
   htmlr_listdir(dir, d, dt, ft, lev);
257807
   
257807
+  free(err);
257807
   return size;
257807
 }
257807
 
257807
diff --git a/json.c b/json.c
257807
index 4b15e0d..8c71324 100644
257807
--- a/json.c
257807
+++ b/json.c
257807
@@ -98,8 +98,7 @@ off_t json_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
   while(*dir) {
257807
     if (!noindent) json_indent(lev);
257807
 
257807
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
257807
-    else mt = (*dir)->mode & S_IFMT;
257807
+    mt = (*dir)->mode & S_IFMT;
257807
     for(t=0;ifmt[t];t++)
257807
       if (ifmt[t] == mt) break;
257807
     fprintf(outfile,"{\"type\":\"%s\"", ftype[t]);
257807
@@ -141,7 +140,7 @@ off_t json_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 	    if (*(*dir)->lnk == '/')
257807
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
257807
 	    else {
257807
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
257807
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
257807
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
257807
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
257807
 	      listdir(path,dt,ft,lev+1,dev);
257807
@@ -181,7 +180,7 @@ off_t json_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 {
257807
   struct _info **dir;
257807
   off_t size = 0;
257807
-  char *err;
257807
+  char *err = NULL;
257807
 
257807
   dir = getfulltree(d, lev, dev, &size, &err;;
257807
 
257807
@@ -189,6 +188,7 @@ off_t json_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 
257807
   jsonr_listdir(dir, d, dt, ft, lev);
257807
 
257807
+  free(err);
257807
   return size;
257807
 }
257807
 
257807
@@ -211,8 +211,7 @@ void jsonr_listdir(struct _info **dir, char *d, int *dt, int *ft, u_long lev)
257807
   while(*dir) {
257807
     if (!noindent) json_indent(lev);
257807
 
257807
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
257807
-    else mt = (*dir)->mode & S_IFMT;
257807
+    mt = (*dir)->mode & S_IFMT;
257807
     for(t=0;ifmt[t];t++)
257807
       if (ifmt[t] == mt) break;
257807
     fprintf(outfile,"{\"type\":\"%s\"", ftype[t]);
257807
diff --git a/tree.c b/tree.c
257807
index 03140fe..73dd101 100644
257807
--- a/tree.c
257807
+++ b/tree.c
257807
@@ -882,7 +882,7 @@ struct _info **unix_getfulltree(char *d, u_long lev, dev_t dev, off_t *size, cha
257807
 	    if (*(*dir)->lnk == '/')
257807
 	      (*dir)->child = unix_getfulltree((*dir)->lnk,lev+1,dev,&((*dir)->size),&((*dir)->err));
257807
 	    else {
257807
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
257807
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
257807
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
257807
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
257807
 	      (*dir)->child = unix_getfulltree(path,lev+1,dev,&((*dir)->size),&((*dir)->err));
257807
diff --git a/unix.c b/unix.c
257807
index ca5f76f..9476307 100644
257807
--- a/unix.c
257807
+++ b/unix.c
257807
@@ -129,7 +129,7 @@ off_t unix_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 	    if (*(*dir)->lnk == '/')
257807
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
257807
 	    else {
257807
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
257807
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
257807
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
257807
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
257807
 	      listdir(path,dt,ft,lev+1,dev);
257807
@@ -162,7 +162,7 @@ off_t unix_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 {
257807
   struct _info **dir;
257807
   off_t size = 0;
257807
-  char *err;
257807
+  char *err = NULL;
257807
   
257807
   dir = getfulltree(d, lev, dev, &size, &err;;
257807
 
257807
@@ -170,6 +170,7 @@ off_t unix_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 
257807
   r_listdir(dir, d, dt, ft, lev);
257807
 
257807
+  free(err);
257807
   return size;
257807
 }
257807
 
257807
diff --git a/xml.c b/xml.c
257807
index 32f3c0c..512eed7 100644
257807
--- a/xml.c
257807
+++ b/xml.c
257807
@@ -106,8 +106,7 @@ off_t xml_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
   while(*dir) {
257807
     if (!noindent) xml_indent(lev);
257807
 
257807
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
257807
-    else mt = (*dir)->mode & S_IFMT;
257807
+    mt = (*dir)->mode & S_IFMT;
257807
     for(t=0;ifmt[t];t++)
257807
       if (ifmt[t] == mt) break;
257807
     fprintf(outfile,"<%s", ftype[t]);
257807
@@ -145,7 +144,7 @@ off_t xml_listdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 	    if (*(*dir)->lnk == '/')
257807
 	      listdir((*dir)->lnk,dt,ft,lev+1,dev);
257807
 	    else {
257807
-	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->name)+1024));
257807
+	      if (strlen(d)+strlen((*dir)->lnk)+2 > pathsize) path=xrealloc(path,pathsize=(strlen(d)+strlen((*dir)->lnk)+1024));
257807
 	      if (fflag && !strcmp(d,"/")) sprintf(path,"%s%s",d,(*dir)->lnk);
257807
 	      else sprintf(path,"%s/%s",d,(*dir)->lnk);
257807
 	      listdir(path,dt,ft,lev+1,dev);
257807
@@ -181,7 +180,7 @@ off_t xml_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
 {
257807
   struct _info **dir;
257807
   off_t size = 0;
257807
-  char *err;
257807
+  char *err = NULL;
257807
   
257807
   dir = getfulltree(d, lev, dev, &size, &err;;
257807
   
257807
@@ -189,6 +188,7 @@ off_t xml_rlistdir(char *d, int *dt, int *ft, u_long lev, dev_t dev)
257807
   
257807
   xmlr_listdir(dir, d, dt, ft, lev);
257807
   
257807
+  free(err);
257807
   return size;
257807
 }
257807
 
257807
@@ -211,8 +211,7 @@ void xmlr_listdir(struct _info **dir, char *d, int *dt, int *ft, u_long lev)
257807
   while(*dir) {
257807
     if (!noindent) xml_indent(lev);
257807
 
257807
-    if ((*dir)->lnk) mt = (*dir)->mode & S_IFMT;
257807
-    else mt = (*dir)->mode & S_IFMT;
257807
+    mt = (*dir)->mode & S_IFMT;
257807
     for(t=0;ifmt[t];t++)
257807
       if (ifmt[t] == mt) break;
257807
     fprintf(outfile,"<%s", ftype[t]);
257807
-- 
257807
2.17.2
257807