summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2024-01-24 21:19:56 +0100
committerraveit65 <[email protected]>2024-01-31 23:36:40 +0100
commited5d540bf64fafbf9266b28f1156ce3ce2ba3038 (patch)
tree021b6c2c929683cb077209118360c0c6fed25204
parentd39e5c2ef97352e4385b9cec69032bfc0124050f (diff)
downloadengrampa-ed5d540bf64fafbf9266b28f1156ce3ce2ba3038.tar.bz2
engrampa-ed5d540bf64fafbf9266b28f1156ce3ce2ba3038.tar.xz
rar: Simplify and merge duplicate code
Merge version matching for rar and unrar. This is ever so slightly slower in theory for unrar 5.x because there's an additional unnecessary `sscanf()` call, but it's not actually gonna matter, and saves quite a bit of duplicated logic. This also makes the matching a bit more safe by verifying `sscanf()` actually worked, and avoids using a uninitialized `version` value due to an unexpected input. Finally, this makes the parsing a bit more strict by requiring a version number after the `RAR` and `UNRAR` line prefixes -- leading not to using the uninitialized version variable. This will be required by the upcoming unrar-free support as it reports a `RAR archive ...` line that would have matched the `RAR` version check.
-rw-r--r--src/fr-command-rar.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c
index d6a724e..7e69fd9 100644
--- a/src/fr-command-rar.c
+++ b/src/fr-command-rar.c
@@ -194,35 +194,19 @@ process_line (char *line,
g_return_if_fail (line != NULL);
if (! rar_comm->list_started) {
- if (strncmp (line, "RAR ", 4) == 0) {
- int version;
- sscanf (line, "RAR %d.", &version);
- rar_comm->rar5 = (version >= 5);
-
- if (version > 5)
- date_newstyle = TRUE;
- else if (version == 5)
- {
- sscanf (line, "RAR 5.%d ", &version);
- if (version >= 30)
- date_newstyle = TRUE;
- }
+ int version = 0;
- }
- else if (strncmp (line, "UNRAR ", 6) == 0) {
- int version;
- sscanf (line, "UNRAR %d.", &version);
+ if (sscanf (line, "RAR %d.", &version) == 1 || sscanf (line, "UNRAR %d.", &version) == 1) {
rar_comm->rar5 = (version >= 5);
if (version > 5)
date_newstyle = TRUE;
- else if (version == 5)
+ else if (version == 5 && (sscanf (line, "RAR 5.%d ", &version) == 1 ||
+ sscanf (line, "UNRAR 5.%d ", &version) == 1))
{
- sscanf (line, "UNRAR 5.%d ", &version);
if (version >= 30)
date_newstyle = TRUE;
}
-
}
else if (strncmp (line, "--------", 8) == 0) {
rar_comm->list_started = TRUE;