Before we start, it's important to say that your concern is not irrational. If this were to happen, or if your plane's control systems were to otherwise malfunction in a dangerous manner, your life would genuinely be in danger.
You aren't the first person to have thought of this, though. For this reason, we have a category of control systems we describe technically as safety related, and there is an entire branch of engineering called safety engineering dedicated to formally assessing these systems and trying to prevent accidents. This includes airplane control systems, but also anti-lock brakes, medical devices, and any other system where people could be harmed by it going wrong. The degree to which people can be harmed by this is formally assessed as a Safety Integrity Level based on risk. The risk is a combination of how likely the event is, how bad the outcome will be, and whether the people involved can take any mitigating action, and it is assessed for every way a safety related system can misbehave.
Note that this assessment may not be as intuitive as you'd think. I once worked on a chaff and flare dispenser system for military aircraft. You would think that the risk of failing to fire countermeasures and the pilot being shot down would be your major risk - but the safety assessment (we used an FMEA) showed that the pilot had other mitigating options such as armour and an ejector seat, getting shot down is a chance they'd already accepted when they took the job, and the risk of a crashing plane hitting buildings was miniscule and something that had already been institutionally accepted as part of having an air force. The most serious risk was actually that the system would misfire whilst an armourer was reloading it, because then they'd get a volley of 36 shotgun shells to the head at close range. The armourer did not sign up to taking that chance, and there was no practical way to protect them. As a result, our system had to default to not firing if there were any discrepancies.
There are many ways to ensure reliability. Redundancy is the most popular one. You can have multiple sensors in multiple locations, so the system can always work out what's going on if one (or more, perhaps) should fail. There are usually multiple actuators for important flight surfaces, or multiple flight surfaces where the aircraft can remain in control if one or more are damaged. Passenger planes generally have multiple engines too, and multiple fuel tanks which can be isolated from each other in case of damage. In a number of cases there may be multiple control systems which "vote" on the right action, so one malfunctioning unit will be ignored. In the extreme case, each control system may even have been programmed by a different software team, so that a bug in one team's software is extremely unlikely to be present in another team's software. And there may be other backup systems in place such as mechanical controls.
Another good mitigating method is training. It's perfectly acceptable for things to go wrong if the people operating it are able to deal with that failure and keep going. It's important not to underestimate how good people can be. People can and do also cause failures, so training can also be a case of telling them "don't do that". Large aircraft are relatively slow to respond to controls, so it's relatively common that pilots can overcorrect and make things worse. For some commercial aircraft, the standard response taught to pilots in case of instability is to let go of the stick and allow the aircraft to correct itself.
It's worth noting that both these factors are why the Boeing-737MAX disasters are so bad, to the extent that there should be criminal charges brought against the people individually and the organisation collectively. The system concerned did not use redundant inputs, even though they were available; the impact of the system failing to respond correctly was not assessed nor mitigated; and the crew were given no training in how to deal with its failure, nor even told that it existed. In the UK, the crime of "corporate manslaughter" exists to prosecute exactly these kind of failures.
The other element to all this though is quality, so that you try to make sure the systems don't go wrong in the first place. The reliability of software is almost entirely dependent on the quantity of reviewing and testing that takes place. I'm currently working on software for scientific equipment, and I reckon to spend around 10-20% of my development time on testing. PCs and mobile phones will be about the same. When I worked on automotive and aerospace systems, this was entirely reversed - we reckoned to spend around 5-10% of our time on coding, 10-20% of our time on design, and the rest of our time went on reviewing and testing.
Change control is also radically more locked down. Microsoft may release an upgrade and then do damage control on the few cases where it misbehaves, and sneak in a few extra features at the same time. In safety-related development though, you don't change a single line of code without formal sign-off that (a) everyone understands what that change will do, (b) that this change fixes this bug and does not change anything else, and (c) that this change is even needed. Many bug triage sessions involve us spotting bugs where we eventually decide that the impact of the bug is tiny (perhaps we're 10ms later turning on a warning light for example), but the risk of trying to fix the bug could potentially be high if we happened to get it wrong, so it is safer for this trivial bug to stick around.
As the Boeing-737MAX case shows us, all these processes are only worth a damn if people follow them. The processes exist though, and they are best practise in an industry of tens of thousands of engineers worldwide which has plenty of formal standards internationally to establish this. Failing to follow these standards is almost by definition gross negligence, and most countries have laws which allow prosecution of people and companies who are negligent to this degree. Most engineers would like to do a good job anyway; but the laws ensure an organisation as a whole stays honest and doesn't cut corners.