ellis morning editor 




once upon a time, a client contacted trick r. and asked him to figure out why files were disappearing from their website. 




the seemingly innocent task proved to be a swan-dive into a sewer of bad php, unsanitized user input, and plain-text passwords stored in the database, among other vulnerabilities. however, the following conditional took the cake for awfulness. what better way to ensure a record is really gone than by running the delete query a bunch of times? if( $_request['task'] == "delete_single" && preg_match("/^([0-9]+)$/", $_request['id'], $reg) ) { $qry = " delete from department where id=".$_request['id']; mysql_query( $qry ); $qry = " delete from department where id=".$_request['id']; mysql_query( $qry ); $qry = " delete from department where id=".$_request['id']; mysql_query( $qry ); $qry = " delete from department where id=".$_request['id']; mysql_query( $qry ); $qry = " delete from department where id=".$_request['id']; mysql_query($qry); $qry1="select * from department where id ='".$_request['id']."'"; $query=mysql_query($qry1); while($data=mysql_fetch_array($query)){ $qry = "delete from department where id=".$data['id']; mysql_query( $qry ); $qry = " delete from department where id=".$data['id']; mysql_query( $qry ); } $qry = " delete from department where id='".$_request['id']."'"; mysql_query( $qry ); $qry2="select * from department_login where pid ='".$_request['id']."'"; $query=mysql_query($qry2); while($data=mysql_fetch_array($query)){ $qry = "delete from department_login where pid=".$data['id']; mysql_query( $qry ); $qry = " delete from department_login where pid=".$data['id']; mysql_query( $qry ); } $qry = " delete from department_login where pid='".$_request['id']."'"; mysql_query( $qry ); $qry3="select * from files where pid ='".$_request['id']."'"; $query=mysql_query($qry3); while($data=mysql_fetch_array($query)){ $qry = "delete from files where pid=".$data['id']; mysql_query( $qry ); $qry = " delete from files where pid=".$data['id']; mysql_query( $qry ); } $qry = " delete from files where pid='".$_request['id']."'"; mysql_query( $qry ); $qry4="select * from pdf where pid ='".$_request['id']."'"; $query=mysql_query($qry4); while($data=mysql_fetch_array($query)){ $qry = "delete from pdf where pid=".$data['id']; mysql_query( $qry ); $qry = " delete from pdf where pid=".$data['id']; mysql_query( $qry ); } $qry = " delete from pdf where pid='".$_request['id']."'"; mysql_query( $qry ); $errormsg = " record deleted successfully !! "; } [advertisement] infrastructure as code built from the start with first-class windows functionality and an intuitive, visual user interface. download otter today!
codesod: repeat delete
ellis morning