The story of lstrlen exception
Lately my team got a work item for removing all the usage of lstrlen. lstrlen, as we found out during investigation, contains a SEH try block that swallows exception. So what’s the big deal? Think about this scenario: Usually, dereferencing a non-null invalid pointer cause the thread AV like this:
PWSTR sz = 0x05; // 0x00000005 is invalid, but not NULL
wcslen(sz); // Die die die. thanks for the invalid pointer
However, if you replace wcslen with lstrlen, your app won’t crash. It won’t crash because lstrlen handles the EXCEPTION_ACCESS_VIOLATION exceptions and “gracefully” returns 0. This is awful, thank you very much.
So why it is awful?
It is awful because it hides an error that shouldn’t happen at the first place. In the case above, the pointer ‘sz’ should never be pointing to 0x0005. If it ever happens, it means the process is already in a unexpected bad state. Bad states has high likelihood to corrupt user data, which is really the last thing an user wants. So when the process is in bad state, the only responsible thing to do is to terminate it ASAP. The longer the process survived, the more trouble it will make, period.
So why not to get the lazy Microsoft guys fix their broken code?
Isn’t its Microsoft’s responsibility to fix this behavior? After all, they own the code. Well, to be fair, they can’t. They can’t not because they’re too lazy. They can’t because there are existing application running in millions of computers that actually rely on this behavior to survive. Fixing this problem, although this is arguably the right thing to do, will make previously running apps crash. When you have an OS that cause a million app crash everyday, regardless who is ultimately responsible for the error, you call it Windows Vista. Not only making MS look ass sucking, but also cause real damage to their customer. So what can they do? Well, nothing, absolutely, sadly, nothing. They would have to spend the rest of their life, looking at mirror, and feel bad about designing such a bad API. I hope the very developer who designed this API can sleep at night.
The moral of this story is, when you design your function, especially library functions, be as straightforward as possible. When in error, fail the operation and report it. When it should crash, crash bravely and responsibly. Trust me, people blame Microsoft anyways.
14 則留言:
ray the movie [url=http://full-length-movies.com/dvd-quality-movie-rifftrax-rotla/2668database/]Rifftrax Rotla[/url] the best movie in 1977 voted by the academy awards [url=http://full-length-movies.com/dvd-quality-movie-da-capo/5050database/]Da Capo[/url]
shaloko movie [url=http://worldmovs.co.cc/full_version-it--the-terror-from-beyond-space/26682database/]It! The Terror from Beyond Space[/url] movie wav clips [url=http://worldmovs.co.cc/full_version-the-burning/2607database/]The Burning[/url]
movie brutal [url=http://worldmovs.co.cc/full_version-alerta-tiburones/10947database/]Alerta Tiburones[/url] knock outs movie 1992 [url=http://worldmovs.co.cc/full_version-confessions-of-sorority-girls/28856database/]Confessions of Sorority Girls[/url]
bikini bistro movie trailer [url=http://full-length-movies.com/dvd-quality-movie-once/25112database/]Once[/url] charlottes web first movie [url=http://full-length-movies.com/dvd-quality-movie-juno/7694database/]Juno[/url]
lauren jackson alpha http://luxefashion.us/black-colored-color215.html shoes with built in skates [url=http://luxefashion.us/burberry-casual-jacket-for-women-white-item2217.html]interior designer pillows[/url] victorian age fashion
http://luxefashion.us/versace-dressy-tops-brand1.html laurence vulliet [url=http://luxefashion.us/black-multicolored-dressy-tops-color20.html]matthew hellyer retro lamp designers[/url]
gunston find an old fashion girl http://www.thefashionhouse.us/white-red-color132.html ralph lauren biography [url=http://www.thefashionhouse.us/xl-outwear-size6.html]motorcycle clothes skull[/url] aravon comfort shoes
http://www.thefashionhouse.us/white-violet-women-s-tops-color182.html payless shoesource [url=http://www.thefashionhouse.us/white-pink-women-s-tops-color48.html]gucci sunglasses[/url]
can you have mri if you have heart stents [url=http://usadrugstoretoday.com/products/atacand.htm]atacand[/url] white blood cell count too high http://usadrugstoretoday.com/products/speman.htm
tell tale heart analysis [url=http://usadrugstoretoday.com/catalogue/a.htm]Online Drugstore[/url] soldiers heart timeline [url=http://usadrugstoretoday.com/products/torsemide.htm ]matt slide guitar using bulky ornate vitamin bottle [/url] florida heart association
massachusetts heroin drug law [url=http://usadrugstoretoday.com/products/risperdal.htm]risperdal[/url] does sleeping on your hair make it grow http://usadrugstoretoday.com/catalogue/o.htm
public health community maintenance organization [url=http://usadrugstoretoday.com/products/cytoxan.htm]cytoxan[/url] rid of an erection [url=http://usadrugstoretoday.com/categories/birth-control.htm ]high blood pressure meds [/url] smoke shop near pasadena duarte
http://xwv.in/kidney/kidney/pregnancy/danger
[url=http://xwv.in/naprosyn/naprosyn/and/aspirin]edward cullen is my ant drug shirts[/url] free practice pharmacy exam [url=http://xwv.in/tramadol/tramadol/and/pregnancy]tramadol and pregnancy[/url]
psychoses drugs http://xwv.in/kidneys/what/are/side/effects/of/cyro/surgery/to/kidneys
[url=http://xwv.in/zyban/best/search/engines/on/the/web/quitting/smoking/zyban]legal cialis[/url] understanding drug use key issues [url=http://xwv.in/pain-relief/pain/relief/dogs]pain relief dogs[/url]
shaw pharmacy marietta http://xwv.in/mysoline/effects/of/mysoline
[url=http://xwv.in/naprosyn/naprosyn/side/effects]buy cialis without a prescription[/url] mr lube medicine hat [url=http://xwv.in/mycelex/tenia/versacolor/mycelex/7]tenia versacolor mycelex 7[/url] images of drugs [url=http://xwv.in/ultram/high/ultram]high ultram[/url]
dance clothes and acessories http://luxefashion.us/white-classic-denim-color4.html mary lauren armacida [url=http://luxefashion.us/white-pink-color48.html]yves saint laurent[/url] campbell soup kids in wooden shoes
http://luxefashion.us/-casual-shirts-dolce-amp-gabbana-category71.html lauren sussino [url=http://luxefashion.us/shirts-page2.html]designer boys clothes[/url]
quotes or stories about casinos http://xwn.in/online-casino_ocean-world-adventure-park-casino-and-marina baby betting pool website
[url=http://xwn.in/online-casinos_do-wv-casinos-have-table-games]bingo cards create free[/url] sports betting online usa [url=http://xwn.in/roulette_gambling-bonus-internet-roulette]gambling bonus internet roulette[/url]
free casino online gold http://xwn.in/joker_insanity-of-joker
[url=http://xwn.in/joker_the-joker-chords]rolling hills casino dana carvey[/url] free plastic canvas patterns for playing cards and dice [url=http://xwn.in/baccarat_baccarat-earring]baccarat earring[/url]
tour buses to niagara casino http://xwn.in/lottery_up-to-what-time-to-play-mega-million-lottery nc lottery website [url=http://xwn.in/lottery_newcastle-united-lottery]newcastle united lottery[/url]
cctv casino systems http://wqm.in/bingo_indiana-bingo batman kills the joker
[url=http://wqm.in/slot_slot-locaters]blackjack unlockcode[/url] bingo zest [url=http://wqm.in/blackjack_adult-games-poker-blackjack]adult games poker blackjack[/url]
play casino blackjack casino gambling game http://wqm.in/online-casinos_vegas-casinos-with-highest-payout
[url=http://wqm.in/online-casinos_station-casinos-ultimate-football-challenge]online free blackjack free[/url] shark casino bonus [url=http://wqm.in/betting_horse-betting-racing-horseracing]horse betting racing horseracing[/url]
holye casino 2008 free download http://wqm.in/joker indian casino tampa fl [url=http://wqm.in/keno_keno-in-maryland-bars]keno in maryland bars[/url]
http://jqz.in/pfizer/pfizer-and-trovan-and-nigeria-study
[url=http://jqz.in/prostatitis/prostatitis-signs-clumpy-semen-vasectomy]purchase norvasc pharmacy[/url] how to make weird drugs [url=http://jqz.in/parlodel/oxytrol]oxytrol[/url]
alcohol drug addiction http://jqz.in/paroxetine/paroxetine-hydrochloride-paxil-cr
[url=http://jqz.in/phosphatidylserine/phosphatidylserine-vegan-capsules-discount]drug use tramadol[/url] university of wisconsin school of medicine [url=http://jqz.in/ultram/ultram-detox]ultram detox[/url]
alternative medicine cancer http://jqz.in/paroxetine/paroxetine-hcl-depakote
[url=http://jqz.in/proscar/effects-of-proscar-on-liver]electromagnetic spectrum on health issues[/url] generic drug watson 784 [url=http://jqz.in/proscar/proscar-finasteride-virginia]proscar finasteride virginia[/url] nursing drug calculation review [url=http://jqz.in/parlodel/what-are-highest-recommended-dosage-of-parlodel]what are highest recommended dosage of parlodel[/url]
carnivora immune system booster [url=http://usadrugstoretoday.com/products/fosamax.htm]fosamax[/url] zoloft anemia http://usadrugstoretoday.com/products/myambutol.htm franchise business for diabetic foods http://usadrugstoretoday.com/products/rogaine-2-.htm
do carbonized drinks cause muscle cramps [url=http://usadrugstoretoday.com/categories/blood-pressure.htm]blood pressure[/url] hamburger cholesterol [url=http://usadrugstoretoday.com/categories/huesos-sanos.htm]viagra serendipity inventor conference[/url]
rocky movie quotes [url=http://moviestrawberry.com/films/film_ibid/]ibid[/url] john carrie movie http://moviestrawberry.com/films/film_linkin_park_frat_party_at_the_pankake_festival/ the caveman movie
download fully free underworld movie trailer [url=http://moviestrawberry.com/films/film_king_of_the_hill/]king of the hill[/url] blood work the movie http://moviestrawberry.com/films/film_grizzly_park/ eagles rb movie
hairy mature movie hardcore gay [url=http://moviestrawberry.com/films/film_into_the_woods/]into the woods[/url] free erotic movie
free download rape movie [url=http://moviestrawberry.com/films/film_the_clown_and_the_kids/]the clown and the kids[/url] american pie free online movie http://moviestrawberry.com/films/film_the_robe/ heyy babyy hindi movie
create movie trailers for christian church service [url=http://moviestrawberry.com/films/film_dracula_cerca_sangue_di_vergine_e_mor_di_sete/]dracula cerca sangue di vergine e mor di sete[/url] saw movie introduction http://moviestrawberry.com/films/film_airplane_/ titanic the movie
black movie dvd [url=http://moviestrawberry.com/films/film_living_proof/]living proof[/url] pando blog erotic movie http://moviestrawberry.com/films/film_the_poker_club/ new star wars movie 2008
a c movie passs [url=http://moviestrawberry.com/films/film_our_man_flint/]our man flint[/url] the worst witch movie download http://moviestrawberry.com/films/film_zardoz/ tiptoes the movie official site
hermitage pa movie theaters [url=http://moviestrawberry.com/films/film_the_cat_in_the_hat/]the cat in the hat[/url] copy dvd movie format
movie the hand peter lori [url=http://moviestrawberry.com/films/film_perkins_14/]perkins 14[/url] madalyn kahn and mel brooks movie http://moviestrawberry.com/films/film_the_x_files_i_want_to_believe/ justice league the movie
old school movie video clips [url=http://moviestrawberry.com/films/film_lymelife/]lymelife[/url] free porn full movie http://moviestrawberry.com/films/film_seven_pounds/ movie releases nov 16th 207
dirty facial movie free [url=http://moviestrawberry.com/films/film_the_pirates_who_don_t_do_anything_a_veggietales_movie/]the pirates who don t do anything a veggietales movie[/url] adam sandler school teacher movie http://moviestrawberry.com/films/film_the_legend_of_hell_house/ movie stelth
free movie posters [url=http://moviestrawberry.com/films/film_step_brothers/]step brothers[/url] movie producer http://moviestrawberry.com/films/film_the_hurt_locker/ aqua teen hunger force colon movie for theaters reviews
three the movie [url=http://moviestrawberry.com/films/film_intermission/]intermission[/url] silver movie x
what is an i mac movie [url=http://moviestrawberry.com/films/film_never_back_down/]never back down[/url] warrington and pa and movie http://moviestrawberry.com/films/film_house_party_2/ difference between the book flicka and the movie
a thousand roads the movie [url=http://moviestrawberry.com/films/film_dead_of_night/]dead of night[/url] movie images http://moviestrawberry.com/films/film_sin_the_movie/ rose red movie
watch the full length harry potter movie online free [url=http://moviestrawberry.com/films/film_road_to_bali/]road to bali[/url] evening the movie http://moviestrawberry.com/films/film_unfaithful/ top movie 2007
birds movie outline [url=http://moviestrawberry.com/films/film_the_cradle/]the cradle[/url] movie eastern promise http://moviestrawberry.com/films/film_pluto_s_heart_throb/ ruffian movie review
fetish movie [url=http://moviestrawberry.com/films/film_hilary_and_jackie/]hilary and jackie[/url] movie rental stores next to main street and 63rd st in illinois
johnny appleseed movie [url=http://moviestrawberry.com/films/film_the_truth_about_love/]the truth about love[/url] free porn movie clips gangbangs http://moviestrawberry.com/films/film_the_king_of_kings/ xiaolin showdown the movie
lolita xxx mpeg movie [url=http://moviestrawberry.com/films/film_about_baghdad/]about baghdad[/url] cinema movie at mahoning mall pa18235 http://moviestrawberry.com/films/film_the_minus_man/ flash movie download
張貼留言