Commit 6b52b7ba72cfbb085cc1afc134a682172f2c747a

Authored by 娄高锋
1 parent 09464c44

改掉sql拼接(sql注入漏洞)。

src/main/java/com/bsth/service/impl/BusIntervalServiceImpl.java
@@ -100,9 +100,14 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -100,9 +100,14 @@ public class BusIntervalServiceImpl implements BusIntervalService {
100 100
101 try { 101 try {
102 102
103 - String sql = "select * from bsth_c_s_sp_info_real where schedule_date_str >= '"+startDate+"' and schedule_date_str <= '"+endDate+"'"; 103 + List<String> objList = new ArrayList<String>();
  104 + String sql = "select * from bsth_c_s_sp_info_real where schedule_date_str >= ? and schedule_date_str <= ?";
  105 + objList.add(startDate);
  106 + objList.add(endDate);
  107 +
104 if(line.length() != 0){ 108 if(line.length() != 0){
105 - sql += " and xl_bm = '"+line+"'"; 109 + sql += " and xl_bm = ?";
  110 + objList.add(line);
106 } 111 }
107 if(times.length() != 0){ 112 if(times.length() != 0){
108 String[] split = times.split("-"); 113 String[] split = times.split("-");
@@ -117,16 +122,19 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -117,16 +122,19 @@ public class BusIntervalServiceImpl implements BusIntervalService {
117 } 122 }
118 } 123 }
119 if(company.length() != 0){ 124 if(company.length() != 0){
120 - sql += " and gs_bm = '"+company+"'"; 125 + sql += " and gs_bm = ?";
  126 + objList.add(company);
121 } 127 }
122 if(subCompany.length() != 0){ 128 if(subCompany.length() != 0){
123 - sql += " and fgs_bm = '"+subCompany+"'"; 129 + sql += " and fgs_bm = ?";
  130 + objList.add(subCompany);
124 } 131 }
125 if(normal){ 132 if(normal){
126 sql += " and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks'"; 133 sql += " and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks'";
127 } 134 }
128 135
129 list = jdbcTemplate.query(sql, 136 list = jdbcTemplate.query(sql,
  137 + objList.toArray(),
130 new RowMapper<ScheduleRealInfo>(){ 138 new RowMapper<ScheduleRealInfo>(){
131 @Override 139 @Override
132 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException { 140 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
@@ -222,14 +230,20 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -222,14 +230,20 @@ public class BusIntervalServiceImpl implements BusIntervalService {
222 }); 230 });
223 231
224 if(model.length() != 0){ 232 if(model.length() != 0){
225 -// sql = "select * from bsth_c_s_ttinfo_detail where ttinfo = '"+model+"' and bc_type != 'in' and bc_type != 'out'";  
226 - sql = "select id from bsth_c_s_sp_info where tt_info = '" + model + "' and bc_type != 'in' and bc_type != 'out'" +  
227 - " and bc_type != 'ldks' and schedule_date >= '"+startDate+"' and schedule_date <= '"+endDate+"'"; 233 + List<String> objList2 = new ArrayList<String>();
  234 + sql = "select id from bsth_c_s_sp_info where tt_info = ? and bc_type != 'in' and bc_type != 'out'" +
  235 + " and bc_type != 'ldks' and schedule_date >= ? and schedule_date <= ?";
  236 + objList2.add(model);
  237 + objList2.add(startDate);
  238 + objList2.add(endDate);
  239 +
228 if(line.length() != 0){ 240 if(line.length() != 0){
229 - sql += " and xl_bm = '"+line+"'"; 241 + sql += " and xl_bm = ?";
  242 + objList2.add(line);
230 } 243 }
231 244
232 ttList = jdbcTemplate.query(sql, 245 ttList = jdbcTemplate.query(sql,
  246 + objList2.toArray(),
233 new RowMapper<Long>(){ 247 new RowMapper<Long>(){
234 @Override 248 @Override
235 public Long mapRow(ResultSet rs, int rowNum) throws SQLException { 249 public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
@@ -303,17 +317,22 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -303,17 +317,22 @@ public class BusIntervalServiceImpl implements BusIntervalService {
303 Map<Long, Set<ChildTaskPlan>> schMap = new HashMap<Long, Set<ChildTaskPlan>>(); 317 Map<Long, Set<ChildTaskPlan>> schMap = new HashMap<Long, Set<ChildTaskPlan>>();
304 List<ChildTaskPlan> list = new ArrayList<ChildTaskPlan>(); 318 List<ChildTaskPlan> list = new ArrayList<ChildTaskPlan>();
305 319
  320 + List<Object> objList = new ArrayList<Object>();
306 String sql = "select id,cc_id,mileage_type,destroy,destroy_reason," + 321 String sql = "select id,cc_id,mileage_type,destroy,destroy_reason," +
307 " mileage,type1,type2,schedule from bsth_c_s_child_task" + 322 " mileage,type1,type2,schedule from bsth_c_s_child_task" +
308 " where 1=1"; 323 " where 1=1";
  324 +
309 if(schedule1 != null && schedule1 > 0){ 325 if(schedule1 != null && schedule1 > 0){
310 - sql += " and schedule >= '"+schedule1+"'"; 326 + sql += " and schedule >= ?";
  327 + objList.add(schedule1);
311 } 328 }
312 if(schedule2 != null && schedule2 > 0){ 329 if(schedule2 != null && schedule2 > 0){
313 - sql += " and schedule <= '"+schedule2+"'"; 330 + sql += " and schedule <= ?";
  331 + objList.add(schedule2);
314 } 332 }
315 333
316 list = jdbcTemplate.query(sql, 334 list = jdbcTemplate.query(sql,
  335 + objList.toArray(),
317 new RowMapper<ChildTaskPlan>(){ 336 new RowMapper<ChildTaskPlan>(){
318 @Override 337 @Override
319 public ChildTaskPlan mapRow(ResultSet rs, int rowNum) throws SQLException { 338 public ChildTaskPlan mapRow(ResultSet rs, int rowNum) throws SQLException {
@@ -354,10 +373,12 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -354,10 +373,12 @@ public class BusIntervalServiceImpl implements BusIntervalService {
354 String line = map.get("line").toString(); 373 String line = map.get("line").toString();
355 374
356 try { 375 try {
357 -  
358 - String sql = "select start_station_name, end_station_name from bsth_c_line where line_code = '"+line+"'"; 376 + List<String> objList = new ArrayList<String>();
  377 + String sql = "select start_station_name, end_station_name from bsth_c_line where line_code = ?";
  378 + objList.add(line);
359 379
360 list = jdbcTemplate.query(sql, 380 list = jdbcTemplate.query(sql,
  381 + objList.toArray(),
361 new RowMapper<Map<String, Object>>(){ 382 new RowMapper<Map<String, Object>>(){
362 @Override 383 @Override
363 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { 384 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
@@ -393,16 +414,22 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -393,16 +414,22 @@ public class BusIntervalServiceImpl implements BusIntervalService {
393 String ttId = map.get("ttId").toString(); 414 String ttId = map.get("ttId").toString();
394 415
395 try { 416 try {
  417 + List<String> objList = new ArrayList<String>();
396 String sql = "select td.lp, lp.lp_name from bsth_c_s_ttinfo_detail td" + 418 String sql = "select td.lp, lp.lp_name from bsth_c_s_ttinfo_detail td" +
397 " left join bsth_c_s_gbi lp on td.lp = lp.id" + 419 " left join bsth_c_s_gbi lp on td.lp = lp.id" +
398 " left join bsth_c_line cl on cl.id = td.xl where 1=1"; 420 " left join bsth_c_line cl on cl.id = td.xl where 1=1";
399 - if(line.length() != 0)  
400 - sql += " and cl.line_code = '"+line+"'";  
401 - if(ttId.length() != 0)  
402 - sql += " and td.ttinfo = '"+ttId+"'"; 421 + if(line.length() != 0){
  422 + sql += " and cl.line_code = ?";
  423 + objList.add(line);
  424 + }
  425 + if(ttId.length() != 0){
  426 + sql += " and td.ttinfo = ?";
  427 + objList.add(ttId);
  428 + }
403 sql += " group by td.lp, lp.lp_name"; 429 sql += " group by td.lp, lp.lp_name";
404 430
405 list = jdbcTemplate.query(sql, 431 list = jdbcTemplate.query(sql,
  432 + objList.toArray(),
406 new RowMapper<Map<String, Object>>(){ 433 new RowMapper<Map<String, Object>>(){
407 @Override 434 @Override
408 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { 435 public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
@@ -2238,11 +2265,14 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -2238,11 +2265,14 @@ public class BusIntervalServiceImpl implements BusIntervalService {
2238 endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); 2265 endDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
2239 } 2266 }
2240 try { 2267 try {
2241 -  
2242 - String sql = "select * from bsth_c_s_sp_info_real where schedule_date_str"  
2243 - + " >= '"+startDate+"' and schedule_date_str <= '"+endDate+"'"; 2268 + List<String> objList = new ArrayList<String>();
  2269 + String sql = "select * from bsth_c_s_sp_info_real where schedule_date_str >= ? and schedule_date_str <= ?";
  2270 + objList.add(startDate);
  2271 + objList.add(endDate);
  2272 +
2244 if(line.length() != 0){ 2273 if(line.length() != 0){
2245 - sql += " and xl_bm = '"+line+"'"; 2274 + sql += " and xl_bm = ?";
  2275 + objList.add(line);
2246 } 2276 }
2247 if(sfqr == 1 && times.length() != 0){ 2277 if(sfqr == 1 && times.length() != 0){
2248 String[] split = times.split("-"); 2278 String[] split = times.split("-");
@@ -2257,14 +2287,17 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -2257,14 +2287,17 @@ public class BusIntervalServiceImpl implements BusIntervalService {
2257 } 2287 }
2258 } 2288 }
2259 if(company.length() != 0){ 2289 if(company.length() != 0){
2260 - sql += " and gs_bm = '"+company+"'"; 2290 + sql += " and gs_bm = ?";
  2291 + objList.add(company);
2261 } 2292 }
2262 if(subCompany.length() != 0){ 2293 if(subCompany.length() != 0){
2263 - sql += " and fgs_bm = '"+subCompany+"'"; 2294 + sql += " and fgs_bm = ?";
  2295 + objList.add(subCompany);
2264 } 2296 }
2265 sql += " and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks'"; 2297 sql += " and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks'";
2266 2298
2267 list = jdbcTemplate.query(sql, 2299 list = jdbcTemplate.query(sql,
  2300 + objList.toArray(),
2268 new RowMapper<ScheduleRealInfo>(){ 2301 new RowMapper<ScheduleRealInfo>(){
2269 @Override 2302 @Override
2270 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException { 2303 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
@@ -3052,20 +3085,30 @@ public class BusIntervalServiceImpl implements BusIntervalService { @@ -3052,20 +3085,30 @@ public class BusIntervalServiceImpl implements BusIntervalService {
3052 if(map.get("sfyy")!=null) 3085 if(map.get("sfyy")!=null)
3053 sfyy = map.get("sfyy").toString().trim(); 3086 sfyy = map.get("sfyy").toString().trim();
3054 3087
  3088 + List<String> objList = new ArrayList<String>();
3055 String sql = "select id, cl_zbh, fcsj, fcsj_actual, j_gh, j_name, lp_name, qdz_name, " + 3089 String sql = "select id, cl_zbh, fcsj, fcsj_actual, j_gh, j_name, lp_name, qdz_name, " +
3056 "schedule_date_str, xl_name, zdsj, zdsj_actual, fgs_bm, fgs_name, gs_name, xl_dir, xl_bm " + 3090 "schedule_date_str, xl_name, zdsj, zdsj_actual, fgs_bm, fgs_name, gs_name, xl_dir, xl_bm " +
3057 "from bsth_c_s_sp_info_real " + 3091 "from bsth_c_s_sp_info_real " +
3058 - "where schedule_date_str >= '"+startDate+"' and schedule_date_str <= '"+endDate+"' " + 3092 + "where schedule_date_str >= ? and schedule_date_str <= ? " +
3059 "and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks' and cc_service = 0"; 3093 "and bc_type != 'in' and bc_type != 'out' and bc_type != 'ldks' and cc_service = 0";
  3094 + objList.add(startDate);
  3095 + objList.add(endDate);
3060 3096
3061 - if(company.length() != 0)  
3062 - sql += " and gs_bm = '"+company+"'";  
3063 - if(subCompany.length() != 0)  
3064 - sql += " and fgs_bm = '"+subCompany+"'";  
3065 - if(line.length() != 0)  
3066 - sql += " and xl_bm = '"+line+"'"; 3097 + if(company.length() != 0){
  3098 + sql += " and gs_bm = ?";
  3099 + objList.add(company);
  3100 + }
  3101 + if(subCompany.length() != 0){
  3102 + sql += " and fgs_bm = ?";
  3103 + objList.add(subCompany);
  3104 + }
  3105 + if(line.length() != 0){
  3106 + sql += " and xl_bm = ?";
  3107 + objList.add(line);
  3108 + }
3067 3109
3068 List<ScheduleRealInfo> list = jdbcTemplate.query(sql, 3110 List<ScheduleRealInfo> list = jdbcTemplate.query(sql,
  3111 + objList.toArray(),
3069 new RowMapper<ScheduleRealInfo>(){ 3112 new RowMapper<ScheduleRealInfo>(){
3070 @Override 3113 @Override
3071 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException { 3114 public ScheduleRealInfo mapRow(ResultSet rs, int rowNum) throws SQLException {