Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

return from gosub halts a BAT file **HOW**?!?!?!?!

Jul
576
10
Why the heck would this fail to return from a gosub? That makes no sense.

And it only happens in one of my sessions, not the others.

How can a session be broken such that return from a subroutine simply exits the bat?
Seems like a bug, or some obscure feature I can’t possibly fathom the purpose of, or some sort of weird console attack (that i somehow accidentally did?) that should be mitigated so this doesn’t happen.



Code:
goto :skip
         :refresh_current_lyric_provider_metadatas [opt]
                iff "%CURRENT_LYRIC_PROVIDER%" == "GENIUS" then
                        *set CURRENT_LYRIC_PROVIDER=GENIUS
                        *set CURRENT_LYRIC_PROVIDER_DISPLAY=Genius
                        *set OTHER_LYRIC_PROVIDER=SYNCEDLYRICS
                        *set OTHER_LYRIC_PROVIDER_DISPLAY=SyncedLyrics
                else
                        *set CURRENT_LYRIC_PROVIDER=SYNCEDLYRICS
                        *set CURRENT_LYRIC_PROVIDER_DISPLAY=SyncedLyrics
                        *set OTHER_LYRIC_PROVIDER=GENIUS
                        *set OTHER_LYRIC_PROVIDER_DISPLAY=Genius
                endiff
        return
:skip

*echo "about to gosub.... why is this not coming back?"
*pause
gosub refresh_current_lyric_provider_metadatas
*echo "why is this echo statement never displaying?"
 
Bad session look like this:

1776518942081.webp


How is this possible? How did things get broken such that return simply halts the script instead of returning?
 
Good session look like this:
1776518990927.webp


In a good session, the "return" from the sub works, and we end up with the echo statement displaying at the end.
 
Not reproducible here.

There are several reasons why a batch file would be exiting around a GOSUB / RETURN, but most (if not all) of them should be displaying an error message.
  • GOSUB label not found
  • The batch file has been deleted, moved, or renamed (this would only affect BAT and CMD files, not BTMs)
  • Another process has locked the batch file (this would only affect BAT and CMD files, not BTMs)
  • Maximum nesting limit has been exceeded
  • Something threw an exception in the subroutine. (Could be TCC, a plugin, injected code from another app, or a Windows API.)
 
Not reproducible here.

There are several reasons why a batch file would be exiting around a GOSUB / RETURN, but most (if not all) of them should be displaying an error message.
  • GOSUB label not found

It’s found and verified as found by debug statements.

  • The batch file has been deleted, moved, or renamed (this would only affect BAT and CMD files, not BTMs)
Was never deleted

  • Another process has locked the batch file (this would only affect BAT and CMD files, not BTMs)
Not the case. I did this over and over anyway. And the fact that I can edit the bat file means it’s not locked ;)

  • Maximum nesting limit has been exceeded
No nesting was done.
  • Something threw an exception in the subroutine. (Could be TCC, a plugin, injected code from another app, or a Windows API.)
As you could see from the code, all we are doing is setting environment variables.

I’m sorry, but it’s 100% not any of those reasons. Wish I knew the real reason.

The same bat file runs just fine in another tab.

I may have lost the corrupted tab by now, but... There’s a code vulnerability here.
 
The same BAT file should not have 2 different results in 2 different tabs absent any of those aforementioned factors...
 
Back
Top