diff options
author | midipix <writeonce@midipix.org> | 2021-05-02 15:43:55 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2021-05-02 15:56:08 +0000 |
commit | 32fd48eab4d183042b5557ea03d06cc9ba0248d5 (patch) | |
tree | dba019668111117364e87716c1f356fe52cc1fa6 | |
parent | 0f1f34a3bf7a84fa408d8eead025dae7aa0c055a (diff) | |
download | slibtool-32fd48eab4d183042b5557ea03d06cc9ba0248d5.tar.bz2 slibtool-32fd48eab4d183042b5557ea03d06cc9ba0248d5.tar.xz |
heuristics: slbt_get_lconf_flags(): enhanced the string-scanning logic.
-rw-r--r-- | src/internal/slibtool_lconf_impl.c | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/src/internal/slibtool_lconf_impl.c b/src/internal/slibtool_lconf_impl.c index 25d6041..9cb86a4 100644 --- a/src/internal/slibtool_lconf_impl.c +++ b/src/internal/slibtool_lconf_impl.c @@ -629,7 +629,6 @@ int slbt_get_lconf_flags( const char * cap; uint64_t optshared; uint64_t optstatic; - int optlenmax; int optsharedlen; int optstaticlen; const char * optsharedstr; @@ -657,10 +656,6 @@ int slbt_get_lconf_flags( mark = addr; cap = &mark[st.st_size]; - /* hard-coded options in the generated libtool precede the code */ - if (st.st_size >= (optlenmax = strlen("build_libtool_libs=yes\n"))) - cap -= optlenmax; - /* scan */ optshared = 0; optstatic = 0; @@ -672,43 +667,61 @@ int slbt_get_lconf_flags( optstaticlen = strlen(optstaticstr); for (; mark && mark<cap; ) { - if (!strncmp(mark,optsharedstr,optsharedlen)) { + if (!optshared && (cap - mark < optsharedlen)) { + mark = 0; + + } else if (!optstatic && (cap - mark < optstaticlen)) { + mark = 0; + + } else if (!optshared && !strncmp(mark,optsharedstr,optsharedlen)) { mark += optsharedlen; - if ((mark[0]=='n') + if ((cap - mark >= 3) + && (mark[0]=='n') && (mark[1]=='o') - && (mark[2]=='\n')) + && (mark[2]=='\n') + && (mark = &mark[3])) optshared = SLBT_DRIVER_DISABLE_SHARED; - if ((mark[0]=='y') + else if ((cap - mark >= 4) + && (mark[0]=='y') && (mark[1]=='e') && (mark[2]=='s') - && (mark[3]=='\n')) + && (mark[3]=='\n') + && (mark = &mark[4])) optshared = SLBT_DRIVER_SHARED; - } else if (!strncmp(mark,optstaticstr,optstaticlen)) { + if (!optshared) + mark--; + + } else if (!optstatic && !strncmp(mark,optstaticstr,optstaticlen)) { mark += optstaticlen; - if ((mark[0]=='n') + if ((cap - mark >= 3) + && (mark[0]=='n') && (mark[1]=='o') - && (mark[2]=='\n')) + && (mark[2]=='\n') + && (mark = &mark[3])) optstatic = SLBT_DRIVER_DISABLE_STATIC; - if ((mark[0]=='y') + else if ((cap - mark >= 4) + && (mark[0]=='y') && (mark[1]=='e') && (mark[2]=='s') - && (mark[3]=='\n')) + && (mark[3]=='\n') + && (mark = &mark[4])) optstatic = SLBT_DRIVER_STATIC; - } - if (optshared && optstatic) - mark = 0; - - else { + if (!optstatic) + mark--; + } else { for (; (mark<cap) && (*mark!='\n'); ) mark++; mark++; } + + if (optshared && optstatic) + mark = 0; } munmap(addr,st.st_size); |