Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

partitions.lib line 222/1024 syntax error and invalid arithmetic operator #45

Closed
De4DMaN opened this issue Mar 26, 2019 · 14 comments
Closed

Comments

@De4DMaN
Copy link

De4DMaN commented Mar 26, 2019

Precise error message
/c/adb/Adebar/lib/partitions.lib: line 222: / 1024: syntax error: operand expected (error token is "/ 1024")
")syntax error: invalid arithmetic operator (error token is "
Full log: https://pastebin.com/ULv8s1Kd

Expected behavior
No errors/warnings being thrown.

Desktop

  • OS: Windows 7 x64
  • Bash Version: mintty / cygwin64 2.9.9 and GIT Bash 4.4.19(2)
  • Adebar Version: latest commit 7178d7c
  • Configuration settings made: changed DEVICE_NAME to "XZ1" and DEVICE_IP to local IP

Smartphone

  • Device: Sony Xperia XZ1 Compact
  • OS Version: Android 9, security patch from February 1
  • ROM: stock 47.2.A.8.24

Additional context
Have exactly the same bug if running under Mac OS X High Sierra with MacPorts bash 2.5.4

@IzzySoft
Copy link
Owner

Thanks for reporting! Unfortunately I cannot test with either (have no Mac, no Windows). But unless "bash 2.5.4" is no spelling error, on that Mac it cannot work: Adebar requires at least Bash 4.

The line reported for the error to have occured means there must be some problem with the "partition output". If you could debug that (or at least help narrowing down), please play with _fsProcMtd() starting at line 20:

  • in line 21, insert echo "USING: $1" and run again (to find out whether it's /proc/mtd or /proc/emmc)
  • then from the command line, run `adb shell "cat $src 2>/dev/null" > "/sdcard/partinfo.txt" (attach this file here so I can take a look)

if you want to go further,

  • before line 41 insert echo "LINE: '${azeile[0]//\:/}'"
  • before line 60, insert `echo "EVAL: 'MTD_NAME[${counter}]=${azeile[3]//"/}'"

grab the output and attach it. I have a guess, but I cannot be sure: maybe one of those lines is empty, and you will see something like EVAL: 'MTD_NAME[7]='. We can dig into that then.

@De4DMaN
Copy link
Author

De4DMaN commented Mar 27, 2019

Yes, sorry about that, I meant to say bash 5.0.2(1) from MacPorts 2.5.4.

Adding echo "USING: $1" to line 21 gives this result:
USING: mtd
USING: emmc
And the full log: https://pastebin.com/rpeCRvmz

Running adb shell "cat $src 2>/dev/null" > "/sdcard/partinfo.txt" gives bash: /sdcard/partinfo.txt: No such file or directory. Although if I change "/sdcard/partinfo.txt" to "./partinfo.txt" empty text file is created. Same as running adb shell and then cat $src, nothing is printed to terminal.

Inserting line 41 and 60 modification along the 21st line gives this: https://pastebin.com/fQCjEdgS

@IzzySoft
Copy link
Owner

5.0.2(1) from MacPorts 2.5.4.

Ah, And Oh. I had no chance yet to test with Bash5, but AFAIK that should be no issue.

Adding echo "USING: $1" to line 21 gives this result:

My bad, remembered it wrongly. It's used to check for both. So without context, that wasn't helpful.

Luckily you continued, and the problem might be (at least partly) in line 13 of your pastebin: your device doesn't even allow to read the partition details: cat: /proc/partitions: Permission denied (the empty file is caused by that: we have no details; the error for /sdcard again is my fault: you run the command from your PC, not on-device). Ahem: Did you replace $src by the source (/proc/mtd,/proc/emmc)?

So that might only be possible with root access. But according to those many times the same line errs out, it must have some data from somewhere. -> What does the report give as source for its partition info?

What you also could do (so we see what it got) is duplicate that "error line" (actually line 222 if you remove the debug line again, the one starting with echo) and remove the redirection from the copy, so you get it straight on the command line.

What certainly would avoid that error is adding the following line before line 222:

[[ -z "${MTD_SIZE[${counter}]}" ]] && MTD_SIZE[${counter}]=0

But then you'd have all partitions without size – which we'd better avoid if possible. However I'm afraid your device will only let root see partition details…

@De4DMaN
Copy link
Author

De4DMaN commented Mar 28, 2019

Ahem: Did you replace $src by the source (/proc/mtd,/proc/emmc)?

Oh, sorry about that, my unix command line knowledge is not that good, so I thought $src was some kind of wildcard or reserved value.
So runnin plain old adb shell "cat /proc/mtd" gives cat: /proc/mtd: No such file or directory and adb shell "cat /proc/emmc" gives cat: /proc/emmc: No such file or directory.
Doing a adb shell "ls /proc" gives some denied permissions: https://pastebin.com/TzPpKAN9 and neither mtd or emmc are listed.

And if I understood you correctly modifying lines as follows:
222: echo " * ${MTD_DEV[${counter}]}: ${pname} ($(printf "%'.0f\n" $((${MTD_SIZE[${counter}]} / 1024))) MiB)"
223: echo " * ${MTD_DEV[${counter}]}: ${pname} ($(printf "%'.0f\n" $((${MTD_SIZE[${counter}]} / 1024))) MiB)" >> "$1"
gives this log: https://pastebin.com/gy9g7ayg

Could you explain what would be the drawback of backuping and restoring with current error present or having partitions without size?

@IzzySoft
Copy link
Owner

No effects on backup. Partition info is 1) just partition INFO and 2) for the scripts to backup the partitions. App backups are not affected.

So I see you cannot access /proc at all (not without root – and you didn't tell whether your device is rooted; but if not, you could not backup the partitions anyway). So the sane thing to do would be turning that feature off (MK_PARTINFO=0 in your config, see the end of this block in the wiki).

If you first wish to check how much info you could obtain, please insert the line

[[ -z "${MTD_SIZE[${counter}]}" ]] && MTD_SIZE[${counter}]=0

directly before line 222. If the result turns out to be "useful", I'd add that to the code for cases like this. Oh yes, from your second pastebin I see it is, so that's what we should do:

* /dev/block/sda47: (FOTAKernel) (0 MiB)

is still useful info, as it at least tells you at least what that partition is used for.

Could you give that a try? Remove the other debug code (echos) you've added during this experiment, and add that line. Let me know the outcome, and if we have to fix more places which throw errors.

Thanks for digging in!

@De4DMaN
Copy link
Author

De4DMaN commented Mar 28, 2019

Device is not rooted.

Both setting MK_PARTINFO=0 or adding [[ -z "${MTD_SIZE[${counter}]}" ]] && MTD_SIZE[${counter}]=0 removes the operand expected error, but the ")syntax error: invalid arithmetic operator (error token is " persists either way.

How can I determine the usefulness of newly added line 222? Can you assist me with a use case or a short instruction of what I should (or should not) expect. (Since I'm going to factory reset my phone after this either way, because the latest firmware update butchered some of the user/account related setting.)

Thank you for being this helpful! :)

@IzzySoft
Copy link
Owner

How can I determine the usefulness of newly added line 222?

You could take a look at the resulting documentation. It's in Markdown format, so you probably need a Markdown viewer for "full effect" – but as Markdown format is easy, a text editor would suffice.

As for the second error (which I thought was in conjunction to the other): The error message doesn't tell where it does occur, so it's hard to pin. It's not related to the one we just tackled. To narrow it down: Could you please disable one feature after another until it disappears (or go the other way round: disabling all and enabling one after the other until it appears), so we can at least see what module causes it?

(helpful approach: uses halves. That is, turn half of; no change means the other half is guilty (continue "halving" that). Error gone means the culprit is among the disabled (enable half of them again and check))

Thank you for being this helpful!

Gladly! If I could reproduce it would save us some ping-pong and would be fixed faster. But without your help I cannot fix it at all – so thanks for your patience and staying with me!

if you have none: Github uses Markdown. You could simply copy-paste it to a comment here and check the preview. But take care what you "save" then 😜

@IzzySoft
Copy link
Owner

IzzySoft commented Mar 28, 2019

PS: You could also increase the log level to maximum, and then check what gets looged immediately before and after that error. The config keyword is PROGRESS, and the max level used in Adebar is AFAIR 5, so PROGRESS=5 in your config should offer some more details on the console. And save you from disabling/enabling too many features to figure. If you make another pastebin with that, I should be able to tell you which modules could be relevant. As you didn't change much in your config yet, that should be easy.

@De4DMaN
Copy link
Author

De4DMaN commented Mar 31, 2019

The problematic property is MK_DEVICEINFO=1 setting it to 0 removes the error. Filtered log with PROGRESS=5 and MK_DEVICEINFO=1 is as follows: https://pastebin.com/vzvA0pwX (removed most of the app data, since no errors were thrown, except for 2 where something strange happened).

@IzzySoft
Copy link
Owner

That indeed narrows it down to between lines 288 and 307 in lib/deviceinfo.lib. The only "arithmetic operations" there are comparisons in the test statements. So may I again ask you for some debug details: in line 288 (i.e. after the line doProgress " + misc details" 3), please insert:

echo "ro.adb.secure: '${DEVPROP[ro.adb.secure]}', ro.secure: '${DEVPROP[ro.secure]}'"
echo "ro.build.selinux: '${DEVPROP[ro.build.selinux]}'"

Those are the only 3 variables used in "arithmetic operations" in the segment indicated by your pastebin. One of those values seems to be non-numerical here (or empty).

Oh, of course please set MK_DEVICEINFO=1 again or we'll see nothing 😄

@De4DMaN
Copy link
Author

De4DMaN commented Mar 31, 2019

Removed all the apps debug log, since it's virtually the same, and the result is: https://pastebin.com/Eb5YM8i3 I'm guessing you are interested in lines:
', ro.secure: '1
ro.build.selinux: ''

@IzzySoft
Copy link
Owner

IzzySoft commented Apr 1, 2019

Yes, the second one is the kind of what I expected. The first one is a bit irritating: where did the "prefix" go? Especially the literal ro.adb.secure: '. The value of that probably is empty as well.

Can you try with the latest code I've just committed (just updated 2 files in lib/)? Does that fix the issue for you?

@De4DMaN
Copy link
Author

De4DMaN commented Apr 1, 2019

Yes, works like a charm! Thank you! If you need any additional logs, I will gladly supply them.

@IzzySoft
Copy link
Owner

IzzySoft commented Apr 1, 2019

Thanks a lot! You provided excellent logs so we could tackle this issue. Unless there's something else open, I'd say we close this issue. Glad it worked out that well, with just 2 lines of code added 😃

@De4DMaN De4DMaN closed this as completed Apr 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants