avatar
mikhailnov has added 42dce9b074
rpm-5.4.10-trigtrans_avoid_alloca_as_stack_overflows (Patch222)

alloca fails with 121 008 objects

... ... --- a/lib/psm.c
... ... +++ b/lib/psm.c
... ... @@ -1904,7 +1904,8 @@ static rpmRC runScriptTriggersLoop(rpmpsm psm, rpmTag tagno, int arg2)
1904 1904
    rpmfi fi = NULL;
1905 1905
    rpmds sourceDs = memset(alloca(sizeof(*sourceDs)), 0, sizeof(*sourceDs));
1906 1906
    char * depName = NULL;
1907
    char * evr;
1907
    char * evr = NULL;
1908
    char * evr_allocated = NULL;
1908 1909
    char * ptr = NULL;
1909 1910
    ARGI_t instances = NULL;
1910 1911
    rpmmi mi;
... ... @@ -1920,15 +1921,26 @@ static rpmRC runScriptTriggersLoop(rpmpsm psm, rpmTag tagno, int arg2)
1921 1921
    else
1922 1922
	n = ts->orderCount;
1923 1923
1924
    evr = memset(alloca(n * 64 * sizeof(*evr)), 0, n * 64 * sizeof(*evr));
1925
    ptr = evr;
1926 1924
    sourceDs->tagN = tagno;
1927 1925
    sourceDs->Type = tagName(tagno);
1928 1926
    sourceDs->Count = n;
1929 1927
    sourceDs->i = -1;
1930
    sourceDs->N = memset(alloca(n * sizeof(*sourceDs->N)), 0, n * sizeof(*sourceDs->N));
1931
    sourceDs->EVR = memset(alloca(n * sizeof(*sourceDs->EVR)), 0, n * sizeof(*sourceDs->EVR));
1932
    sourceDs->Flags = (evrFlags *) memset(alloca(n * sizeof(*sourceDs->Flags)), 0, n * sizeof(*sourceDs->Flags));
1928
1929
    /* Avoid stack allocation as it overflows */
1930
    rc = RPMRC_FAIL;
1931
    ptr = evr = evr_allocated = calloc(n * 64, sizeof(*evr));
1932
    if (!evr_allocated)
1933
	goto exit_free;
1934
    sourceDs->N = calloc(n, sizeof(*sourceDs->N));
1935
    if (!sourceDs->N)
1936
	goto exit_free;
1937
    sourceDs->EVR = calloc(n, sizeof(*sourceDs->EVR));
1938
    if (!sourceDs->EVR)
1939
	goto exit_free;
1940
    sourceDs->Flags = calloc(n, sizeof(*sourceDs->Flags));
1941
    if (!sourceDs->Flags)
1942
	goto exit_free;
1943
    rc = RPMRC_OK;
1933 1944
1934 1945
    pi = rpmtsiInit(ts);
1935 1946
    while ((p = rpmtsiNext(pi, psm->goal == PSM_PKGINSTALL ? TR_ADDED : TR_REMOVED)) != NULL) {
... ... @@ -1957,7 +1969,7 @@ static rpmRC runScriptTriggersLoop(rpmpsm psm, rpmTag tagno, int arg2)
1969 1969
    pi = rpmtsiFree(pi);
1970 1970
1971 1971
    if (sourceDs->i == -1)
1972
	return rc;
1972
	goto exit_free;
1973 1973
1974 1974
    /* Fire elements against rpmdb trigger strings. */
1975 1975
    for(sourceDs->i = 0; sourceDs->i < (int)sourceDs->Count; sourceDs->i++) {
... ... @@ -1968,7 +1980,7 @@ static rpmRC runScriptTriggersLoop(rpmpsm psm, rpmTag tagno, int arg2)
1980 1980
1981 1981
1982 1982
	if (!depName || !*depName)
1983
	    return rc;
1983
	    goto exit_free;
1984 1984
1985 1985
	if (_psm_debug)
1986 1986
	    rpmlog(RPMLOG_DEBUG, "--> %s:%d depName: %s tagno: %d ix: %d\n", __FUNCTION__, __LINE__, depName, tagno, sourceDs->i);
... ... @@ -2014,6 +2026,12 @@ static rpmRC runScriptTriggersLoop(rpmpsm psm, rpmTag tagno, int arg2)
2026 2026
2027 2027
    instances = argiFree(instances);
2028 2028
2029
exit_free:
2030
    free(sourceDs->Flags);
2031
    free(sourceDs->EVR);
2032
    free(sourceDs->N);
2033
    free(evr_allocated);
2034
2029 2035
    return rc;
2030 2036
}
2031 2037

Comments