Changeset 4106 for zzuf/trunk/src


Ignore:
Timestamp:
Dec 7, 2009, 7:34:21 PM (10 years ago)
Author:
Sam Hocevar
Message:

Fix memory leaks and infinite loops in the Win32 launcher.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/zzuf.c

    r4100 r4106  
    690690        {
    691691            perror("pipe");
     692            opts->seed++;
    692693            return;
    693694        }
     
    696697    pid = run_process(opts, pipes);
    697698    if(pid < 0)
     699    {
     700        fprintf(stderr, "error launching `%s'\n", opts->newargv[0]);
     701        opts->seed++;
    698702        return;
     703    }
    699704
    700705    /* We’re the parent, acknowledge spawn */
     
    11751180    PIMAGE_DOS_HEADER dos;
    11761181    PIMAGE_NT_HEADERS nt;
    1177     void *file, *map, *base;
     1182    void *file, *map, *base, *ret = NULL;
    11781183
    11791184    file = CreateFile(name, GENERIC_READ, FILE_SHARE_READ,
    11801185                      NULL, OPEN_EXISTING, 0, NULL);
    11811186    if(file == INVALID_HANDLE_VALUE)
    1182         return NULL;
     1187        return ret;
    11831188
    11841189    map = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
     
    11861191    {
    11871192        CloseHandle(file);
    1188         return NULL;
     1193        return ret;
    11891194    }
    11901195
     
    11941199        CloseHandle(map);
    11951200        CloseHandle(file);
    1196         return NULL;
     1201        return ret;
    11971202    }
    11981203
     
    12001205    dos = (PIMAGE_DOS_HEADER)base;
    12011206    nt = (PIMAGE_NT_HEADERS)((char *)base + dos->e_lfanew);
    1202     if(dos->e_magic != IMAGE_DOS_SIGNATURE
    1203       || nt->Signature != IMAGE_NT_SIGNATURE
    1204       || nt->FileHeader.Machine != IMAGE_FILE_MACHINE_I386
    1205       || nt->OptionalHeader.Magic != 0x10b /* IMAGE_NT_OPTIONAL_HDR32_MAGIC */)
    1206     {
    1207         UnmapViewOfFile(base);
    1208         CloseHandle(map);
    1209         CloseHandle(file);
    1210         return NULL;
    1211     }
    1212 
    1213     return (void *)(uintptr_t)(nt->OptionalHeader.ImageBase +
    1214                                  nt->OptionalHeader.AddressOfEntryPoint);
     1207    if(dos->e_magic == IMAGE_DOS_SIGNATURE /* 0x5A4D */
     1208      && nt->Signature == IMAGE_NT_SIGNATURE /* 0x00004550 */
     1209      && nt->FileHeader.Machine == IMAGE_FILE_MACHINE_I386
     1210      && nt->OptionalHeader.Magic == 0x10b /* IMAGE_NT_OPTIONAL_HDR32_MAGIC */)
     1211    {
     1212        ret = (void *)(uintptr_t)(nt->OptionalHeader.ImageBase +
     1213                                  nt->OptionalHeader.AddressOfEntryPoint);
     1214    }
     1215
     1216    UnmapViewOfFile(base);
     1217    CloseHandle(map);
     1218    CloseHandle(file);
     1219
     1220    return ret;
    12151221}
    12161222#endif
Note: See TracChangeset for help on using the changeset viewer.