I think you'll find your answer here
As for B-17's in particular, the waist guns were simple pivot mounts, with no safety bars or stops to the weapon, so the waist gun could be pointed at the wing. I don't know if there was some sort of electromechanical safety if the gun was pointed in a certain direction, but I doubt it.