idle_master icon indicating copy to clipboard operation
idle_master copied to clipboard

NullReferenceException when accessing "steamLogin" cookie

Open opello opened this issue 10 years ago • 7 comments

The latest Idle Master was never able to load the badge page for me, but it seemed like everything should be working according to a Wireshark capture. Then I looked in error.log:

12/22/2015 6:52:55 PM   CookieClient -> GetHttpAsync, for url = http://steamcommunity.com/profiles/76561197992873512/badges/?p=1
System.Net.WebException: An exception occurred during a WebClient request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Net.WebClient.DownloadBitsState.SetResponse(WebResponse response)
   at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at IdleMaster.CookieClient.<GetHttpAsync>d__5.MoveNext()

I did some additional debugging and came up with the fix I'm proposing here. It's too bad that the test isn't a single lookup, but I don't think there will be a large number of cookies to iterate through. If this proposed change is undesirable for that reason I think larger changes to get access to a System.Web.HttpCookieCollection would be required. I also thought about catching the NullReferenceException on the access of the CookieCollection but this seemed cleaner.

opello avatar Dec 23 '15 04:12 opello

+1, should definitely merge @jshackles

NotTsunami avatar Dec 23 '15 05:12 NotTsunami

This works, thanks!

goto1134 avatar Jan 04 '17 11:01 goto1134

By checking the cookie, not the value for a null you do have a single lookup.

treloret avatar Jan 04 '17 12:01 treloret

@treloret I think what you've done in #243 is just fine. I didn't go check the Item[String] exception behavior when implementing my solution and I prefer to "look before you leap" or use "defensive programming" when handling user input which is what I consider cookies. But Item[String] will only raise an ArgumentNullException and the argument is a static string.

Thought this was a similar to a fix that was proposed december 2015, seems I fixed it with a less brute force approach.

I would argue that your implementation is not "less brute force" than mine because of how the Item[String] accessor is implemented.

opello avatar Jan 05 '17 02:01 opello

I updated this PR with a new fix. Instead of iterating the cookie collection directly one lookup is performed and cached locally. The cached instance is tested for null (the original problem) and then for the value "deleted" (the original goal). It worked for me locally.

opello avatar Jan 05 '17 03:01 opello

@opello can you compile?

kaue avatar Jan 05 '17 12:01 kaue

Works nicely

treloret avatar Jan 05 '17 14:01 treloret