From: Bert Vermeulen Date: Mon, 23 Jul 2012 13:08:44 +0000 (+0200) Subject: sr: better file version check X-Git-Tag: dsupstream~762 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c1864d5589749a881d661ab3abfd09cdbb96253d;p=libsigrok.git sr: better file version check Still not really used though. --- diff --git a/session_file.c b/session_file.c index 33364a29..aae31a00 100644 --- a/session_file.c +++ b/session_file.c @@ -48,9 +48,9 @@ SR_API int sr_session_load(const char *filename) struct zip_stat zs; struct sr_dev_inst *sdi; struct sr_probe *probe; - int ret, probenum, devcnt, i, j; + int ret, probenum, devcnt, version, i, j; uint64_t tmp_u64, total_probes, enabled_probes, p; - char **sections, **keys, *metafile, *val, c; + char **sections, **keys, *metafile, *val, s[11]; char probename[SR_MAX_PROBENAME_LEN + 1]; if (!filename) { @@ -65,16 +65,22 @@ SR_API int sr_session_load(const char *filename) } /* check "version" */ + version = 0; if (!(zf = zip_fopen(archive, "version", 0))) { sr_dbg("session file: Not a sigrok session file."); return SR_ERR; } - ret = zip_fread(zf, &c, 1); - if (ret != 1 || c != '1') { + if ((ret = zip_fread(zf, s, 10)) == -1) { sr_dbg("session file: Not a valid sigrok session file."); return SR_ERR; } zip_fclose(zf); + s[ret] = 0; + version = strtoull(s, NULL, 10); + if (version != 1) { + sr_dbg("session file: Not a valid sigrok session file version."); + return SR_ERR; + } /* read "metadata" */ if (zip_stat(archive, "metadata", 0, &zs) == -1) {