diff options
Diffstat (limited to 'src/main/extractor.c')
-rw-r--r-- | src/main/extractor.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/main/extractor.c b/src/main/extractor.c index 5208e3b..3a0e960 100644 --- a/src/main/extractor.c +++ b/src/main/extractor.c | |||
@@ -1174,8 +1174,10 @@ process_requests (struct EXTRACTOR_PluginList *plugin, | |||
1174 | { | 1174 | { |
1175 | char hfn[256]; | 1175 | char hfn[256]; |
1176 | char tfn[256]; | 1176 | char tfn[256]; |
1177 | char sze[256]; | ||
1177 | size_t hfn_len; | 1178 | size_t hfn_len; |
1178 | size_t tfn_len; | 1179 | size_t tfn_len; |
1180 | size_t sze_len; | ||
1179 | char *fn; | 1181 | char *fn; |
1180 | FILE *fin; | 1182 | FILE *fin; |
1181 | void *ptr; | 1183 | void *ptr; |
@@ -1256,6 +1258,15 @@ process_requests (struct EXTRACTOR_PluginList *plugin, | |||
1256 | { | 1258 | { |
1257 | fn = hfn; | 1259 | fn = hfn; |
1258 | } | 1260 | } |
1261 | if (NULL == fgets (sze, sizeof(sze), fin)) | ||
1262 | break; | ||
1263 | if ('s' != sze[0]) | ||
1264 | break; | ||
1265 | sze_len = strlen (sze); | ||
1266 | sze[--sze_len] = '\0'; /* kill newline */ | ||
1267 | size = strtol (&sze[1], NULL, 10); | ||
1268 | if (size == LONG_MIN || size == LONG_MAX || size == 0) | ||
1269 | break; | ||
1259 | do_break = 0; | 1270 | do_break = 0; |
1260 | #ifndef WINDOWS | 1271 | #ifndef WINDOWS |
1261 | if ( (-1 != (shmid = shm_open (fn, O_RDONLY, 0))) && | 1272 | if ( (-1 != (shmid = shm_open (fn, O_RDONLY, 0))) && |
@@ -1268,16 +1279,11 @@ process_requests (struct EXTRACTOR_PluginList *plugin, | |||
1268 | ptr = MapViewOfFile (map, FILE_MAP_READ, 0, 0, 0); | 1279 | ptr = MapViewOfFile (map, FILE_MAP_READ, 0, 0, 0); |
1269 | if (ptr != NULL) | 1280 | if (ptr != NULL) |
1270 | { | 1281 | { |
1271 | size = VirtualQuery (ptr, &mi, sizeof (mi)); | 1282 | if (0 == VirtualQuery (ptr, &mi, sizeof (mi)) || mi.RegionSize < size) |
1272 | if (size == 0) | ||
1273 | { | 1283 | { |
1274 | UnmapViewOfFile (ptr); | 1284 | UnmapViewOfFile (ptr); |
1275 | ptr = NULL; | 1285 | ptr = NULL; |
1276 | } | 1286 | } |
1277 | else | ||
1278 | { | ||
1279 | size = mi.RegionSize; | ||
1280 | } | ||
1281 | } | 1287 | } |
1282 | if (ptr != NULL) | 1288 | if (ptr != NULL) |
1283 | #endif | 1289 | #endif |
@@ -1495,12 +1501,12 @@ start_process (struct EXTRACTOR_PluginList *plugin) | |||
1495 | HANDLE p10_os_inh = INVALID_HANDLE_VALUE, p21_os_inh = INVALID_HANDLE_VALUE; | 1501 | HANDLE p10_os_inh = INVALID_HANDLE_VALUE, p21_os_inh = INVALID_HANDLE_VALUE; |
1496 | 1502 | ||
1497 | plugin->hProcess = NULL; | 1503 | plugin->hProcess = NULL; |
1498 | if (0 != _pipe (p1, 0, _O_BINARY)) | 1504 | if (0 != _pipe (p1, 0, _O_BINARY | _O_NOINHERIT)) |
1499 | { | 1505 | { |
1500 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | 1506 | plugin->flags = EXTRACTOR_OPTION_DISABLED; |
1501 | return; | 1507 | return; |
1502 | } | 1508 | } |
1503 | if (0 != _pipe (p2, 0, _O_BINARY)) | 1509 | if (0 != _pipe (p2, 0, _O_BINARY | _O_NOINHERIT)) |
1504 | { | 1510 | { |
1505 | close (p1[0]); | 1511 | close (p1[0]); |
1506 | close (p1[1]); | 1512 | close (p1[1]); |
@@ -1587,6 +1593,7 @@ start_process (struct EXTRACTOR_PluginList *plugin) | |||
1587 | * actual code of the plugin out-of-process. | 1593 | * actual code of the plugin out-of-process. |
1588 | * | 1594 | * |
1589 | * @param plugin which plugin to call | 1595 | * @param plugin which plugin to call |
1596 | * @param size size of the file mapped by shmfn or tshmfn | ||
1590 | * @param shmfn file name of the shared memory segment | 1597 | * @param shmfn file name of the shared memory segment |
1591 | * @param tshmfn file name of the shared memory segment for the end of the data | 1598 | * @param tshmfn file name of the shared memory segment for the end of the data |
1592 | * @param proc function to call on the meta data | 1599 | * @param proc function to call on the meta data |
@@ -1595,6 +1602,7 @@ start_process (struct EXTRACTOR_PluginList *plugin) | |||
1595 | */ | 1602 | */ |
1596 | static int | 1603 | static int |
1597 | extract_oop (struct EXTRACTOR_PluginList *plugin, | 1604 | extract_oop (struct EXTRACTOR_PluginList *plugin, |
1605 | size_t size, | ||
1598 | const char *shmfn, | 1606 | const char *shmfn, |
1599 | const char *tshmfn, | 1607 | const char *tshmfn, |
1600 | EXTRACTOR_MetaDataProcessor proc, | 1608 | EXTRACTOR_MetaDataProcessor proc, |
@@ -1638,6 +1646,20 @@ extract_oop (struct EXTRACTOR_PluginList *plugin, | |||
1638 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | 1646 | plugin->flags = EXTRACTOR_OPTION_DISABLED; |
1639 | return 0; | 1647 | return 0; |
1640 | } | 1648 | } |
1649 | if (0 >= fprintf (plugin->cpipe_in, | ||
1650 | "s%lu\n", | ||
1651 | size)) | ||
1652 | { | ||
1653 | stop_process (plugin); | ||
1654 | #ifndef WINDOWS | ||
1655 | plugin->cpid = -1; | ||
1656 | #else | ||
1657 | plugin->hProcess = INVALID_HANDLE_VALUE; | ||
1658 | #endif | ||
1659 | if (plugin->flags != EXTRACTOR_OPTION_DEFAULT_POLICY) | ||
1660 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | ||
1661 | return 0; | ||
1662 | } | ||
1641 | fflush (plugin->cpipe_in); | 1663 | fflush (plugin->cpipe_in); |
1642 | while (1) | 1664 | while (1) |
1643 | { | 1665 | { |
@@ -1898,7 +1920,7 @@ extract (struct EXTRACTOR_PluginList *plugins, | |||
1898 | switch (flags) | 1920 | switch (flags) |
1899 | { | 1921 | { |
1900 | case EXTRACTOR_OPTION_DEFAULT_POLICY: | 1922 | case EXTRACTOR_OPTION_DEFAULT_POLICY: |
1901 | if (0 != extract_oop (ppos, fn, | 1923 | if (0 != extract_oop (ppos, (tptr != NULL) ? tsize : size, fn, |
1902 | (tptr != NULL) ? tfn : NULL, | 1924 | (tptr != NULL) ? tfn : NULL, |
1903 | proc, proc_cls)) | 1925 | proc, proc_cls)) |
1904 | { | 1926 | { |
@@ -1912,7 +1934,7 @@ extract (struct EXTRACTOR_PluginList *plugins, | |||
1912 | #endif | 1934 | #endif |
1913 | { | 1935 | { |
1914 | start_process (ppos); | 1936 | start_process (ppos); |
1915 | if (0 != extract_oop (ppos, fn, | 1937 | if (0 != extract_oop (ppos, (tptr != NULL) ? tsize : size, fn, |
1916 | (tptr != NULL) ? tfn : NULL, | 1938 | (tptr != NULL) ? tfn : NULL, |
1917 | proc, proc_cls)) | 1939 | proc, proc_cls)) |
1918 | { | 1940 | { |
@@ -1922,7 +1944,7 @@ extract (struct EXTRACTOR_PluginList *plugins, | |||
1922 | } | 1944 | } |
1923 | break; | 1945 | break; |
1924 | case EXTRACTOR_OPTION_OUT_OF_PROCESS_NO_RESTART: | 1946 | case EXTRACTOR_OPTION_OUT_OF_PROCESS_NO_RESTART: |
1925 | if (0 != extract_oop (ppos, fn, | 1947 | if (0 != extract_oop (ppos, (tptr != NULL) ? tsize : size, fn, |
1926 | (tptr != NULL) ? tfn : NULL, | 1948 | (tptr != NULL) ? tfn : NULL, |
1927 | proc, proc_cls)) | 1949 | proc, proc_cls)) |
1928 | { | 1950 | { |