project
stringclasses
633 values
commit_id
stringlengths
7
81
target
int64
0
1
func
stringlengths
5
484k
cwe
stringclasses
131 values
big_vul_idx
float64
0
189k
idx
int64
0
522k
hash
stringlengths
34
39
size
float64
1
24k
message
stringlengths
0
11.5k
dataset
stringclasses
1 value
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::setMatrix(SplashCoord *matrix) { memcpy(state->matrix, matrix, 6 * sizeof(SplashCoord)); }
CWE-189
1,285
11,848
330330999593770837741897756641730084111
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::setMiterLimit(SplashCoord miterLimit) { state->miterLimit = miterLimit; }
CWE-189
1,286
11,849
68932454016672898327915921501786323991
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::setScreen(SplashScreen *screen) { state->setScreen(screen); }
CWE-189
1,287
11,850
36533782453958917074049361577980022751
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::setSoftMask(SplashBitmap *softMask) { state->setSoftMask(softMask); }
CWE-189
1,288
11,851
114620345886024398075616940591992525376
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::setStrokeAdjust(GBool strokeAdjust) { state->strokeAdjust = strokeAdjust; }
CWE-189
1,289
11,852
276111082441053436141365694986541444828
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::setStrokeAlpha(SplashCoord alpha) { state->strokeAlpha = alpha; }
CWE-189
1,290
11,853
307400608459041367546527900192664229850
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::setStrokePattern(SplashPattern *strokePattern) { state->setStrokePattern(strokePattern); }
CWE-189
1,291
11,854
105562664655747968658986159667617952044
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
SplashError Splash::stroke(SplashPath *path) { SplashPath *path2, *dPath; if (debugMode) { printf("stroke [dash:%d] [width:%.2f]:\n", state->lineDashLength, (double)state->lineWidth); dumpPath(path); } opClipRes = splashClipAllOutside; if (path->length == 0) { return splashErrEmptyPath; } path2 = flattenPath(path, state->matrix, state->flatness); if (state->lineDashLength > 0) { dPath = makeDashedPath(path2); delete path2; path2 = dPath; } if (state->lineWidth == 0) { strokeNarrow(path2); } else { strokeWide(path2); } delete path2; return splashOk; }
CWE-189
1,292
11,855
171903303592689011428704162532045580365
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::strokeNarrow(SplashPath *path) { SplashPipe pipe; SplashXPath *xPath; SplashXPathSeg *seg; int x0, x1, x2, x3, y0, y1, x, y, t; SplashCoord dx, dy, dxdy; SplashClipResult clipRes; int nClipRes[3]; int i; nClipRes[0] = nClipRes[1] = nClipRes[2] = 0; xPath = new SplashXPath(path, state->matrix, state->flatness, gFalse); pipeInit(&pipe, 0, 0, state->strokePattern, NULL, state->strokeAlpha, gFalse, gFalse); for (i = 0, seg = xPath->segs; i < xPath->length; ++i, ++seg) { x0 = splashFloor(seg->x0); x1 = splashFloor(seg->x1); y0 = splashFloor(seg->y0); y1 = splashFloor(seg->y1); if (y0 == y1) { if (x0 > x1) { t = x0; x0 = x1; x1 = t; } if ((clipRes = state->clip->testSpan(x0, x1, y0)) != splashClipAllOutside) { drawSpan(&pipe, x0, x1, y0, clipRes == splashClipAllInside); } } else if (splashAbs(seg->dxdy) > 1) { dx = seg->x1 - seg->x0; dy = seg->y1 - seg->y0; dxdy = seg->dxdy; if (y0 > y1) { t = y0; y0 = y1; y1 = t; t = x0; x0 = x1; x1 = t; dx = -dx; dy = -dy; } if ((clipRes = state->clip->testRect(x0 <= x1 ? x0 : x1, y0, x0 <= x1 ? x1 : x0, y1)) != splashClipAllOutside) { if (dx > 0) { x2 = x0; x3 = splashFloor(seg->x0 + ((SplashCoord)y0 + 1 - seg->y0) * dxdy); drawSpan(&pipe, x2, (x2 <= x3 - 1) ? x3 - 1 : x2, y0, clipRes == splashClipAllInside); x2 = x3; for (y = y0 + 1; y <= y1 - 1; ++y) { x3 = splashFloor(seg->x0 + ((SplashCoord)y + 1 - seg->y0) * dxdy); drawSpan(&pipe, x2, x3 - 1, y, clipRes == splashClipAllInside); x2 = x3; } drawSpan(&pipe, x2, x2 <= x1 ? x1 : x2, y1, clipRes == splashClipAllInside); } else { x2 = x0; x3 = splashFloor(seg->x0 + ((SplashCoord)y0 + 1 - seg->y0) * dxdy); drawSpan(&pipe, (x3 + 1 <= x2) ? x3 + 1 : x2, x2, y0, clipRes == splashClipAllInside); x2 = x3; for (y = y0 + 1; y <= y1 - 1; ++y) { x3 = splashFloor(seg->x0 + ((SplashCoord)y + 1 - seg->y0) * dxdy); drawSpan(&pipe, x3 + 1, x2, y, clipRes == splashClipAllInside); x2 = x3; } drawSpan(&pipe, x1, (x1 <= x2) ? x2 : x1, y1, clipRes == splashClipAllInside); } } } else { dxdy = seg->dxdy; if (y0 > y1) { t = x0; x0 = x1; x1 = t; t = y0; y0 = y1; y1 = t; } if ((clipRes = state->clip->testRect(x0 <= x1 ? x0 : x1, y0, x0 <= x1 ? x1 : x0, y1)) != splashClipAllOutside) { drawPixel(&pipe, x0, y0, clipRes == splashClipAllInside); for (y = y0 + 1; y <= y1 - 1; ++y) { x = splashFloor(seg->x0 + ((SplashCoord)y - seg->y0) * dxdy); drawPixel(&pipe, x, y, clipRes == splashClipAllInside); } drawPixel(&pipe, x1, y1, clipRes == splashClipAllInside); } } ++nClipRes[clipRes]; } if (nClipRes[splashClipPartial] || (nClipRes[splashClipAllInside] && nClipRes[splashClipAllOutside])) { opClipRes = splashClipPartial; } else if (nClipRes[splashClipAllInside]) { opClipRes = splashClipAllInside; } else { opClipRes = splashClipAllOutside; } delete xPath; }
CWE-189
1,293
11,856
4074488222446595802676805797874683476
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void Splash::strokeWide(SplashPath *path) { SplashPath *path2; path2 = makeStrokePath(path, gFalse); fillWithPattern(path2, gFalse, state->strokePattern, state->strokeAlpha); delete path2; }
CWE-189
1,294
11,857
227124125196968178621362159413312979001
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
inline void Splash::transform(SplashCoord *matrix, SplashCoord xi, SplashCoord yi, SplashCoord *xo, SplashCoord *yo) { *xo = xi * matrix[0] + yi * matrix[2] + matrix[4]; *yo = xi * matrix[1] + yi * matrix[3] + matrix[5]; }
CWE-189
1,295
11,858
184701872749877475595045445003335738771
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
inline void Splash::updateModX(int x) { if (x < modXMin) { modXMin = x; } if (x > modXMax) { modXMax = x; } }
CWE-189
1,296
11,859
137815396482762897286202663893154606734
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
inline void Splash::updateModY(int y) { if (y < modYMin) { modYMin = y; } if (y > modYMax) { modYMax = y; } }
CWE-189
1,297
11,860
208117186804662362244793012726075286468
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
Splash::~Splash() { while (state->next) { restoreState(); } delete state; if (vectorAntialias) { delete aaBuf; } }
CWE-189
1,299
11,861
174418230808922697168238511445137074911
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
Guchar SplashBitmap::getAlpha(int x, int y) { return alpha[y * width + x]; }
CWE-189
1,300
11,862
207580560695459925673361902938430948823
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
void SplashBitmap::getPixel(int x, int y, SplashColorPtr pixel) { SplashColorPtr p; if (y < 0 || y >= height || x < 0 || x >= width) { return; } switch (mode) { case splashModeMono1: p = &data[y * rowSize + (x >> 3)]; pixel[0] = (p[0] & (0x80 >> (x & 7))) ? 0xff : 0x00; break; case splashModeMono8: p = &data[y * rowSize + x]; pixel[0] = p[0]; break; case splashModeRGB8: p = &data[y * rowSize + 3 * x]; pixel[0] = p[0]; pixel[1] = p[1]; pixel[2] = p[2]; break; case splashModeXBGR8: p = &data[y * rowSize + 4 * x]; pixel[0] = p[2]; pixel[1] = p[1]; pixel[2] = p[0]; pixel[3] = p[3]; break; case splashModeBGR8: p = &data[y * rowSize + 3 * x]; pixel[0] = p[2]; pixel[1] = p[1]; pixel[2] = p[0]; break; #if SPLASH_CMYK case splashModeCMYK8: p = &data[y * rowSize + 4 * x]; pixel[0] = p[0]; pixel[1] = p[1]; pixel[2] = p[2]; pixel[3] = p[3]; break; #endif } }
CWE-189
1,301
11,863
84823488781850351424258539099395494659
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
SplashError SplashBitmap::writePNMFile(char *fileName) { FILE *f; SplashError e; if (!(f = fopen(fileName, "wb"))) { return splashErrOpenFile; } e = this->writePNMFile(f); fclose(f); return e; }
CWE-189
1,302
11,864
220484713321913025484923635271095923416
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
SplashError SplashBitmap::writePNMFile(FILE *f) { SplashColorPtr row, p; int x, y; switch (mode) { case splashModeMono1: fprintf(f, "P4\n%d %d\n", width, height); row = data; for (y = 0; y < height; ++y) { p = row; for (x = 0; x < width; x += 8) { fputc(*p ^ 0xff, f); ++p; } row += rowSize; } break; case splashModeMono8: fprintf(f, "P5\n%d %d\n255\n", width, height); row = data; for (y = 0; y < height; ++y) { p = row; for (x = 0; x < width; ++x) { fputc(*p, f); ++p; } row += rowSize; } break; case splashModeRGB8: fprintf(f, "P6\n%d %d\n255\n", width, height); row = data; for (y = 0; y < height; ++y) { p = row; for (x = 0; x < width; ++x) { fputc(splashRGB8R(p), f); fputc(splashRGB8G(p), f); fputc(splashRGB8B(p), f); p += 3; } row += rowSize; } break; case splashModeXBGR8: fprintf(f, "P6\n%d %d\n255\n", width, height); row = data; for (y = 0; y < height; ++y) { p = row; for (x = 0; x < width; ++x) { fputc(splashBGR8R(p), f); fputc(splashBGR8G(p), f); fputc(splashBGR8B(p), f); p += 4; } row += rowSize; } break; case splashModeBGR8: fprintf(f, "P6\n%d %d\n255\n", width, height); row = data; for (y = 0; y < height; ++y) { p = row; for (x = 0; x < width; ++x) { fputc(splashBGR8R(p), f); fputc(splashBGR8G(p), f); fputc(splashBGR8B(p), f); p += 3; } row += rowSize; } break; #if SPLASH_CMYK case splashModeCMYK8: break; #endif } return splashOk; }
CWE-189
1,303
11,865
219731902730694833044248943101758108404
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
SplashBitmap::~SplashBitmap() { if (rowSize < 0) { gfree(data + (height - 1) * rowSize); } else { gfree(data); } gfree(alpha); }
CWE-189
1,304
11,866
281171151705053405909742525910048217707
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
GBool SplashFTFont::getGlyph(int c, int xFrac, int yFrac, SplashGlyphBitmap *bitmap, int x0, int y0, SplashClip *clip, SplashClipResult *clipRes) { return SplashFont::getGlyph(c, xFrac, 0, bitmap, x0, y0, clip, clipRes); }
CWE-189
1,305
11,867
115630052649730023939370742137974799935
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
double SplashFTFont::getGlyphAdvance(int c) { SplashFTFontFile *ff; FT_Vector offset; FT_UInt gid; FT_Matrix identityMatrix; ff = (SplashFTFontFile *)fontFile; identityMatrix.xx = 65536; // 1 in 16.16 format identityMatrix.xy = 0; identityMatrix.yx = 0; identityMatrix.yy = 65536; // 1 in 16.16 format offset.x = 0; offset.y = 0; ff->face->size = sizeObj; FT_Set_Transform(ff->face, &identityMatrix, &offset); if (ff->codeToGID && c < ff->codeToGIDLen) { gid = (FT_UInt)ff->codeToGID[c]; } else { gid = (FT_UInt)c; } if (ff->trueType && gid == 0) { return -1; } #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER if (FT_Load_Glyph(ff->face, gid, aa ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT)) { return -1; } #else if (FT_Load_Glyph(ff->face, gid, aa ? FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT)) { return -1; } #endif return ff->face->glyph->metrics.horiAdvance / 64.0 / size; }
CWE-189
1,306
11,868
67871971198538875770815866850823090367
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
SplashPath *SplashFTFont::getGlyphPath(int c) { static FT_Outline_Funcs outlineFuncs = { #if FREETYPE_MINOR <= 1 (int (*)(FT_Vector *, void *))&glyphPathMoveTo, (int (*)(FT_Vector *, void *))&glyphPathLineTo, (int (*)(FT_Vector *, FT_Vector *, void *))&glyphPathConicTo, (int (*)(FT_Vector *, FT_Vector *, FT_Vector *, void *))&glyphPathCubicTo, #else &glyphPathMoveTo, &glyphPathLineTo, &glyphPathConicTo, &glyphPathCubicTo, #endif 0, 0 }; SplashFTFontFile *ff; SplashFTFontPath path; FT_GlyphSlot slot; FT_UInt gid; FT_Glyph glyph; ff = (SplashFTFontFile *)fontFile; ff->face->size = sizeObj; FT_Set_Transform(ff->face, &textMatrix, NULL); slot = ff->face->glyph; if (ff->codeToGID && c < ff->codeToGIDLen) { gid = ff->codeToGID[c]; } else { gid = (FT_UInt)c; } if (ff->trueType && gid == 0) { return NULL; } if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) { return NULL; } if (FT_Get_Glyph(slot, &glyph)) { return NULL; } path.path = new SplashPath(); path.textScale = textScale; path.needClose = gFalse; FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline, &outlineFuncs, &path); if (path.needClose) { path.path->close(); } FT_Done_Glyph(glyph); return path.path; }
CWE-189
1,307
11,869
307726210061055316388503667130262496217
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
static int glyphPathConicTo(const FT_Vector *ctrl, const FT_Vector *pt, void *path) { SplashFTFontPath *p = (SplashFTFontPath *)path; SplashCoord x0, y0, x1, y1, x2, y2, x3, y3, xc, yc; if (!p->path->getCurPt(&x0, &y0)) { return 0; } xc = (SplashCoord)ctrl->x * p->textScale / 64.0; yc = (SplashCoord)ctrl->y * p->textScale / 64.0; x3 = (SplashCoord)pt->x * p->textScale / 64.0; y3 = (SplashCoord)pt->y * p->textScale / 64.0; x1 = (SplashCoord)(1.0 / 3.0) * (x0 + (SplashCoord)2 * xc); y1 = (SplashCoord)(1.0 / 3.0) * (y0 + (SplashCoord)2 * yc); x2 = (SplashCoord)(1.0 / 3.0) * ((SplashCoord)2 * xc + x3); y2 = (SplashCoord)(1.0 / 3.0) * ((SplashCoord)2 * yc + y3); p->path->curveTo(x1, y1, x2, y2, x3, y3); p->needClose = gTrue; return 0; }
CWE-189
1,308
11,870
148376250420087921730782223605565002012
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
static int glyphPathLineTo(const FT_Vector *pt, void *path) { SplashFTFontPath *p = (SplashFTFontPath *)path; p->path->lineTo((SplashCoord)pt->x * p->textScale / 64.0, (SplashCoord)pt->y * p->textScale / 64.0); p->needClose = gTrue; return 0; }
CWE-189
1,309
11,871
128316937912033306003055785015655931186
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
static int glyphPathMoveTo(const FT_Vector *pt, void *path) { SplashFTFontPath *p = (SplashFTFontPath *)path; if (p->needClose) { p->path->close(); p->needClose = gFalse; } p->path->moveTo((SplashCoord)pt->x * p->textScale / 64.0, (SplashCoord)pt->y * p->textScale / 64.0); return 0; }
CWE-189
1,310
11,872
2224360542294480082095337572852615032
null
null
null
poppler
9cf2325fb22f812b31858e519411f57747d39bd8
0
SplashFTFont::~SplashFTFont() { }
CWE-189
1,311
11,873
58980233399151992799214157655404535113
null
null
null
poppler
284a92899602daa4a7f429e61849e794569310b5
0
char *copyString(char *s) { char *s1; s1 = (char *)gmalloc(strlen(s) + 1); strcpy(s1, s); return s1; }
CWE-399
1,312
11,874
273163565827591111290567039135133924428
null
null
null
poppler
284a92899602daa4a7f429e61849e794569310b5
0
void gMemReport(FILE *f) { GMemHdr *p; fprintf(f, "%d memory allocations in all\n", gMemIndex); if (gMemAlloc > 0) { fprintf(f, "%d memory blocks left allocated:\n", gMemAlloc); fprintf(f, " index size\n"); fprintf(f, "-------- --------\n"); for (p = gMemHead; p; p = p->next) { fprintf(f, "%8d %8d\n", p->index, p->size); } } else { fprintf(f, "No memory blocks left allocated\n"); } }
CWE-399
1,313
11,875
179933766916516033191776638654303284868
null
null
null
poppler
284a92899602daa4a7f429e61849e794569310b5
0
char *gstrndup(const char *s, size_t n) { char *s1 = (char*)gmalloc(n + 1); /* cannot return NULL for size > 0 */ s1[n] = '\0'; memcpy(s1, s, n); return s1; }
CWE-399
1,314
11,876
168444376239453475769703135261398650670
null
null
null
shibboleth
6182b0acf2df670e75423c2ed7afe6950ef11c9d
0
pair<const EntityDescriptor*,const RoleDescriptor*> DynamicMetadataProvider::getEntityDescriptor(const Criteria& criteria) const { Category& log = Category::getInstance(SAML_LOGCAT ".MetadataProvider.Dynamic"); bool writeLocked = false; pair<const EntityDescriptor*,const RoleDescriptor*> entity = AbstractMetadataProvider::getEntityDescriptor(criteria); cachemap_t::iterator cit; if (entity.first) { cit = m_cacheMap.find(entity.first->getEntityID()); } else if (criteria.entityID_ascii) { auto_ptr_XMLCh widetemp(criteria.entityID_ascii); cit = m_cacheMap.find(widetemp.get()); } else if (criteria.entityID_unicode) { cit = m_cacheMap.find(criteria.entityID_unicode); } else if (criteria.artifact) { auto_ptr_XMLCh widetemp(criteria.artifact->getSource().c_str()); cit = m_cacheMap.find(widetemp.get()); } else { cit = m_cacheMap.end(); } if (cit != m_cacheMap.end()) { if (time(nullptr) <= cit->second) return entity; } string name; if (criteria.entityID_ascii) { name = criteria.entityID_ascii; } else if (criteria.entityID_unicode) { auto_ptr_char temp(criteria.entityID_unicode); name = temp.get(); } else if (criteria.artifact) { name = criteria.artifact->getSource(); } else { return entity; } if (entity.first) log.info("metadata for (%s) is beyond caching interval, attempting to refresh", name.c_str()); else log.info("resolving metadata for (%s)", name.c_str()); try { auto_ptr<EntityDescriptor> entity2(resolve(criteria)); if (criteria.entityID_unicode && !XMLString::equals(criteria.entityID_unicode, entity2->getEntityID())) { log.error("metadata instance did not match expected entityID"); return entity; } else if (criteria.artifact) { auto_ptr_char temp2(entity2->getEntityID()); const string hashed(SecurityHelper::doHash("SHA1", temp2.get(), strlen(temp2.get()), true)); if (hashed != name) { log.error("metadata instance did not match expected entityID"); return entity; } } else { auto_ptr_XMLCh temp2(name.c_str()); if (!XMLString::equals(temp2.get(), entity2->getEntityID())) { log.error("metadata instance did not match expected entityID"); return entity; } } try { SchemaValidators.validate(entity2.get()); } catch (exception& ex) { log.error("metadata instance failed manual validation checking: %s", ex.what()); throw MetadataException("Metadata instance failed manual validation checking."); } doFilters(*entity2); time_t now = time(nullptr); time_t cmp = now; if (cmp < (std::numeric_limits<int>::max() - 60)) cmp += 60; if (entity2->getValidUntil() && entity2->getValidUntilEpoch() < cmp) throw MetadataException("Metadata was already invalid at the time of retrieval."); log.info("caching resolved metadata for (%s)", name.c_str()); time_t cacheExp = (entity2->getValidUntil() ? entity2->getValidUntilEpoch() : SAMLTIME_MAX) - now; if (entity2->getCacheDuration()) cacheExp = min(cacheExp, entity2->getCacheDurationEpoch()); cacheExp *= m_refreshDelayFactor; if (cacheExp > m_maxCacheDuration) cacheExp = m_maxCacheDuration; else if (cacheExp < m_minCacheDuration) cacheExp = m_minCacheDuration; log.info("next refresh of metadata for (%s) no sooner than %u seconds", name.c_str(), cacheExp); m_lock->unlock(); m_lock->wrlock(); writeLocked = true; emitChangeEvent(*entity2); m_cacheMap[entity2->getEntityID()] = now + cacheExp; cacheExp = SAMLTIME_MAX; unindex(entity2->getEntityID(), true); // actually frees the old instance with this ID indexEntity(entity2.get(), cacheExp); entity2.release(); m_lastUpdate = now; } catch (exception& e) { log.error("error while resolving entityID (%s): %s", name.c_str(), e.what()); if (!writeLocked) { m_lock->unlock(); m_lock->wrlock(); writeLocked = true; } if (entity.first) m_cacheMap[entity.first->getEntityID()] = time(nullptr) + m_minCacheDuration; else if (criteria.entityID_unicode) m_cacheMap[criteria.entityID_unicode] = time(nullptr) + m_minCacheDuration; else { auto_ptr_XMLCh widetemp(name.c_str()); m_cacheMap[widetemp.get()] = time(nullptr) + m_minCacheDuration; } log.warn("next refresh of metadata for (%s) no sooner than %u seconds", name.c_str(), m_minCacheDuration); return entity; } if (writeLocked) { m_lock->unlock(); m_lock->rdlock(); } return getEntityDescriptor(criteria); }
CWE-347
1,317
11,877
245703341626389896032391291362783036935
null
null
null
shibboleth
6182b0acf2df670e75423c2ed7afe6950ef11c9d
0
const XMLObject* DynamicMetadataProvider::getMetadata() const { throw MetadataException("getMetadata operation not implemented on this provider."); }
CWE-347
1,319
11,878
321304436941987452326784277613711794075
null
null
null
shibboleth
6182b0acf2df670e75423c2ed7afe6950ef11c9d
0
void DynamicMetadataProvider::init() { }
CWE-347
1,320
11,879
327561513303132572119468143550696549769
null
null
null
shibboleth
6182b0acf2df670e75423c2ed7afe6950ef11c9d
0
Lockable* DynamicMetadataProvider::lock() { m_lock->rdlock(); return this; }
CWE-347
1,321
11,880
278558332855813041475601775137903274966
null
null
null
shibboleth
6182b0acf2df670e75423c2ed7afe6950ef11c9d
0
EntityDescriptor* DynamicMetadataProvider::resolve(const Criteria& criteria) const { string name; if (criteria.entityID_ascii) { name = criteria.entityID_ascii; } else if (criteria.entityID_unicode) { auto_ptr_char temp(criteria.entityID_unicode); name = temp.get(); } else if (criteria.artifact) { throw MetadataException("Unable to resolve metadata dynamically from an artifact."); } try { DOMDocument* doc=nullptr; auto_ptr_XMLCh widenit(name.c_str()); URLInputSource src(widenit.get()); Wrapper4InputSource dsrc(&src,false); if (m_validate) doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc); else doc=XMLToolingConfig::getConfig().getParser().parse(dsrc); XercesJanitor<DOMDocument> docjanitor(doc); auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true)); docjanitor.release(); EntityDescriptor* entity = dynamic_cast<EntityDescriptor*>(xmlObject.get()); if (!entity) { throw MetadataException( "Root of metadata instance not recognized: $1", params(1,xmlObject->getElementQName().toString().c_str()) ); } xmlObject.release(); return entity; } catch (XMLException& e) { auto_ptr_char msg(e.getMessage()); Category::getInstance(SAML_LOGCAT ".MetadataProvider.Dynamic").error( "Xerces error while resolving entityID (%s): %s", name.c_str(), msg.get() ); throw MetadataException(msg.get()); } }
CWE-347
1,322
11,881
9500884790770483521388659387404129633
null
null
null
shibboleth
6182b0acf2df670e75423c2ed7afe6950ef11c9d
0
void DynamicMetadataProvider::unlock() { m_lock->unlock(); }
CWE-347
1,323
11,882
250155342306252632280898346338795732232
null
null
null
shibboleth
6182b0acf2df670e75423c2ed7afe6950ef11c9d
0
DynamicMetadataProvider::~DynamicMetadataProvider() { clearDescriptorIndex(true); if (m_cleanup_thread) { m_shutdown = true; m_cleanup_wait->signal(); m_cleanup_thread->join(nullptr); delete m_cleanup_thread; delete m_cleanup_wait; m_cleanup_thread = nullptr; m_cleanup_wait = nullptr; } }
CWE-347
1,324
11,883
271575071435776750957608583718658073453
null
null
null
shibboleth
b66cceb0e992c351ad5e2c665229ede82f261b16
0
saml2md::MetadataProvider* SHIBSP_DLLLOCAL DynamicMetadataProviderFactory(const DOMElement* const & e) { return new DynamicMetadataProvider(e); }
CWE-347
1,325
11,884
217788948376924830117544867393827966804
null
null
null
shibboleth
b66cceb0e992c351ad5e2c665229ede82f261b16
0
saml2md::EntityDescriptor* DynamicMetadataProvider::resolve(const saml2md::MetadataProvider::Criteria& criteria) const { #ifdef _DEBUG xmltooling::NDC("resolve"); #endif Category& log=Category::getInstance(SHIBSP_LOGCAT ".MetadataProvider.Dynamic"); string name; if (criteria.entityID_ascii) { name = criteria.entityID_ascii; } else if (criteria.entityID_unicode) { auto_ptr_char temp(criteria.entityID_unicode); name = temp.get(); } else if (criteria.artifact) { if (m_subst.empty() && (m_regex.empty() || m_match.empty())) throw saml2md::MetadataException("Unable to resolve metadata dynamically from an artifact."); name = "{sha1}" + criteria.artifact->getSource(); } if (!m_subst.empty()) { string name2(name); if (!m_hashed.empty()) { name2 = SecurityHelper::doHash(m_hashed.c_str(), name.c_str(), name.length()); } name2 = boost::replace_first_copy(m_subst, "$entityID", m_encoded ? XMLToolingConfig::getConfig().getURLEncoder()->encode(name2.c_str()) : name2); log.info("transformed location from (%s) to (%s)", name.c_str(), name2.c_str()); name = name2; } else if (!m_match.empty() && !m_regex.empty()) { try { RegularExpression exp(m_match.c_str()); XMLCh* temp = exp.replace(name.c_str(), m_regex.c_str()); if (temp) { auto_ptr_char narrow(temp); XMLString::release(&temp); if (name != narrow.get()) { log.info("transformed location from (%s) to (%s)", name.c_str(), narrow.get()); name = narrow.get(); } } } catch (XMLException& ex) { auto_ptr_char msg(ex.getMessage()); log.error("caught error applying regular expression: %s", msg.get()); } } if (XMLString::startsWithI(name.c_str(), "file://")) { MetadataProvider::Criteria baseCriteria(name.c_str()); return saml2md::DynamicMetadataProvider::resolve(baseCriteria); } const MetadataProviderCriteria* mpc = dynamic_cast<const MetadataProviderCriteria*>(&criteria); if (!mpc) throw saml2md::MetadataException("Dynamic MetadataProvider requires Shibboleth-aware lookup criteria, check calling code."); const PropertySet* relyingParty; if (criteria.artifact) relyingParty = mpc->application.getRelyingParty((XMLCh*)nullptr); else if (criteria.entityID_unicode) relyingParty = mpc->application.getRelyingParty(criteria.entityID_unicode); else { auto_ptr_XMLCh temp2(name.c_str()); relyingParty = mpc->application.getRelyingParty(temp2.get()); } SOAPTransport::Address addr(relyingParty->getString("entityID").second, name.c_str(), name.c_str()); const char* pch = strchr(addr.m_endpoint,':'); if (!pch) throw IOException("location was not a URL."); string scheme(addr.m_endpoint, pch-addr.m_endpoint); boost::scoped_ptr<SOAPTransport> transport; try { transport.reset(XMLToolingConfig::getConfig().SOAPTransportManager.newPlugin(scheme.c_str(), addr)); } catch (exception& ex) { log.error("exception while building transport object to resolve URL: %s", ex.what()); throw IOException("Unable to resolve entityID with a known transport protocol."); } transport->setVerifyHost(m_verifyHost); if (m_trust.get() && m_dummyCR.get() && !transport->setTrustEngine(m_trust.get(), m_dummyCR.get())) throw IOException("Unable to install X509TrustEngine into transport object."); Locker credlocker(nullptr, false); CredentialResolver* credResolver = nullptr; pair<bool,const char*> authType=relyingParty->getString("authType"); if (!authType.first || !strcmp(authType.second,"TLS")) { credResolver = mpc->application.getCredentialResolver(); if (credResolver) credlocker.assign(credResolver); if (credResolver) { CredentialCriteria cc; cc.setUsage(Credential::TLS_CREDENTIAL); authType = relyingParty->getString("keyName"); if (authType.first) cc.getKeyNames().insert(authType.second); const Credential* cred = credResolver->resolve(&cc); cc.getKeyNames().clear(); if (cred) { if (!transport->setCredential(cred)) log.error("failed to load Credential into metadata resolver"); } else { log.error("no TLS credential supplied"); } } else { log.error("no CredentialResolver available for TLS"); } } else { SOAPTransport::transport_auth_t type=SOAPTransport::transport_auth_none; pair<bool,const char*> username=relyingParty->getString("authUsername"); pair<bool,const char*> password=relyingParty->getString("authPassword"); if (!username.first || !password.first) log.error("transport authType (%s) specified but authUsername or authPassword was missing", authType.second); else if (!strcmp(authType.second,"basic")) type = SOAPTransport::transport_auth_basic; else if (!strcmp(authType.second,"digest")) type = SOAPTransport::transport_auth_digest; else if (!strcmp(authType.second,"ntlm")) type = SOAPTransport::transport_auth_ntlm; else if (!strcmp(authType.second,"gss")) type = SOAPTransport::transport_auth_gss; else if (strcmp(authType.second,"none")) log.error("unknown authType (%s) specified for RelyingParty", authType.second); if (type > SOAPTransport::transport_auth_none) { if (transport->setAuth(type,username.second,password.second)) log.debug("configured for transport authentication (method=%s, username=%s)", authType.second, username.second); else log.error("failed to configure transport authentication (method=%s)", authType.second); } } pair<bool,unsigned int> timeout = relyingParty->getUnsignedInt("connectTimeout"); transport->setConnectTimeout(timeout.first ? timeout.second : 10); timeout = relyingParty->getUnsignedInt("timeout"); transport->setTimeout(timeout.first ? timeout.second : 20); mpc->application.getServiceProvider().setTransportOptions(*transport); HTTPSOAPTransport* http = dynamic_cast<HTTPSOAPTransport*>(transport.get()); if (http) { pair<bool,bool> flag = relyingParty->getBool("chunkedEncoding"); http->useChunkedEncoding(flag.first && flag.second); http->setRequestHeader("Xerces-C", XERCES_FULLVERSIONDOT); http->setRequestHeader("XML-Security-C", XSEC_FULLVERSIONDOT); http->setRequestHeader("OpenSAML-C", gOpenSAMLDotVersionStr); http->setRequestHeader(PACKAGE_NAME, PACKAGE_VERSION); } try { transport->send(); istream& msg = transport->receive(); DOMDocument* doc=nullptr; StreamInputSource src(msg, "DynamicMetadataProvider"); Wrapper4InputSource dsrc(&src,false); if (m_validate) doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc); else doc=XMLToolingConfig::getConfig().getParser().parse(dsrc); XercesJanitor<DOMDocument> docjanitor(doc); if (!doc->getDocumentElement() || !XMLHelper::isNodeNamed(doc->getDocumentElement(), samlconstants::SAML20MD_NS, saml2md::EntityDescriptor::LOCAL_NAME)) { throw saml2md::MetadataException("Root of metadata instance was not an EntityDescriptor"); } auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true)); docjanitor.release(); saml2md::EntityDescriptor* entity = dynamic_cast<saml2md::EntityDescriptor*>(xmlObject.get()); if (!entity) { throw saml2md::MetadataException( "Root of metadata instance not recognized: $1", params(1,xmlObject->getElementQName().toString().c_str()) ); } xmlObject.release(); return entity; } catch (XMLException& e) { auto_ptr_char msg(e.getMessage()); log.error("Xerces error while resolving location (%s): %s", name.c_str(), msg.get()); throw saml2md::MetadataException(msg.get()); } }
CWE-347
1,326
11,885
256368339488494809987630038332941562011
null
null
null
shibboleth
b66cceb0e992c351ad5e2c665229ede82f261b16
0
virtual ~DynamicMetadataProvider() {}
CWE-347
1,327
11,886
227235960368711045527206464696664383378
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static __be32 *__xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes) { __be32 *p = xdr->p; __be32 *q = p + XDR_QUADLEN(nbytes); if (q > xdr->end || q < p) return NULL; xdr->p = q; return p; }
CWE-119
1,328
11,887
233065251648475173286850435890506478162
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int decode_filename(struct xdr_stream *xdr, char *name, u32 *length) { __be32 *p; u32 count; p = xdr_inline_decode(xdr, 4); if (!p) goto out_overflow; count = ntoh32(net_read_uint32(p)); if (count > 255) goto out_nametoolong; p = xdr_inline_decode(xdr, count); if (!p) goto out_overflow; memcpy(name, p, count); name[count] = 0; *length = count; return 0; out_nametoolong: pr_err("%s: returned a too long filename: %u\n", __func__, count); return -ENAMETOOLONG; out_overflow: pr_err("%s: premature end of packet\n", __func__); return -EIO; }
CWE-119
1,329
11,888
231352033946484304778541296062992015278
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static uint32_t *nfs_add_filename(uint32_t *p, uint32_t filename_len, const char *filename) { *p++ = hton32(filename_len); /* zero padding */ if (filename_len & 3) p[filename_len / 4] = 0; memcpy(p, filename, filename_len); p += DIV_ROUND_UP(filename_len, 4); return p; }
CWE-119
1,331
11,889
127082484813897035434462918345723595582
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static uint32_t *nfs_add_uint32(uint32_t *p, uint32_t val) { *p++ = hton32(val); return p; }
CWE-119
1,332
11,890
63366735390379507623516228522084546310
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static uint32_t *nfs_add_uint64(uint32_t *p, uint64_t val) { uint64_t nval = hton64(val); memcpy(p, &nval, 8); return p + 2; }
CWE-119
1,333
11,891
29017986689839475804648012045253107894
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static struct inode *nfs_alloc_inode(struct super_block *sb) { struct nfs_inode *node; node = xzalloc(sizeof(*node)); if (!node) return NULL; return &node->inode; }
CWE-119
1,334
11,892
268861505658563558681795969109108695103
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_close(struct device_d *dev, FILE *file) { struct file_priv *priv = file->priv; nfs_do_close(priv); return 0; }
CWE-119
1,335
11,893
202905033130912259935580632451859822516
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_fattr3_to_stat(uint32_t *p, struct inode *inode) { uint32_t mode; size_t i; if (!inode) return 0; /* offsetof(struct fattr3, type) = 0 */ switch (ntoh32(net_read_uint32(p + 0))) { case NF3REG: inode->i_mode = S_IFREG; break; case NF3DIR: inode->i_mode = S_IFDIR; break; case NF3BLK: inode->i_mode = S_IFBLK; break; case NF3CHR: inode->i_mode = S_IFCHR; break; case NF3LNK: inode->i_mode = S_IFLNK; break; case NF3SOCK: inode->i_mode = S_IFSOCK; break; case NF3FIFO: inode->i_mode = S_IFIFO; break; default: printf("%s: invalid mode %x\n", __func__, ntoh32(net_read_uint32(p + 0))); return -EIO; } /* offsetof(struct fattr3, mode) = 4 */ mode = ntoh32(net_read_uint32(p + 1)); for (i = 0; i < ARRAY_SIZE(nfs3_mode_bits); ++i) { if (mode & nfs3_mode_bits[i].nfsmode) inode->i_mode |= nfs3_mode_bits[i].statmode; } /* offsetof(struct fattr3, size) = 20 */ inode->i_size = ntoh64(net_read_uint64(p + 5)); return 0; }
CWE-119
1,337
11,894
221639015850859483115846564944312631076
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static const char *nfs_get_link(struct dentry *dentry, struct inode *inode) { struct nfs_inode *ninode = nfsi(inode); struct nfs_priv *npriv = ninode->npriv; int ret; ret = nfs_readlink_req(npriv, &ninode->fh, &inode->i_link); if (ret) return ERR_PTR(ret); return inode->i_link; }
CWE-119
1,338
11,895
321873762240462890471554110568007835573
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_init(void) { rootnfsopts = xstrdup("v3,tcp"); globalvar_add_simple_string("linux.rootnfsopts", &rootnfsopts); return register_fs_driver(&nfs_driver); }
CWE-119
1,339
11,896
271115272517942421763647945059775034732
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_init_inode(struct nfs_priv *npriv, struct inode *inode, unsigned int mode) { struct nfs_inode *ninode = nfsi(inode); ninode->npriv = npriv; inode->i_ino = get_next_ino(); inode->i_mode = mode; switch (inode->i_mode & S_IFMT) { default: return -EINVAL; case S_IFREG: inode->i_op = &nfs_file_inode_operations; inode->i_fop = &nfs_file_operations; break; case S_IFDIR: inode->i_op = &nfs_dir_inode_operations; inode->i_fop = &nfs_dir_operations; inc_nlink(inode); break; case S_IFLNK: inode->i_op = &nfs_symlink_inode_operations; break; } return 0; }
CWE-119
1,340
11,897
62355229576207790039108844698706640088
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_iterate(struct file *file, struct dir_context *ctx) { struct dentry *dentry = file->f_path.dentry; struct inode *dir = d_inode(dentry); struct nfs_priv *npriv = nfsi(dir)->npriv; void *buf = NULL; struct nfs_dir *ndir; struct xdr_stream *xdr; int ret; uint32_t *p, len; ndir = xzalloc(sizeof(*ndir)); ndir->fh = nfsi(dir)->fh; while (1) { /* cookie == 0 and cookieverf == 0 means start of dir */ buf = nfs_readdirattr_req(npriv, ndir); if (!buf) { pr_err("%s: nfs_readdirattr_req failed\n", __func__); ret = -EINVAL; goto out; } xdr = &ndir->stream; while (1) { char name[256]; p = xdr_inline_decode(xdr, 4); if (!p) goto err_eop; if (!net_read_uint32(p)) { /* eof? */ p = xdr_inline_decode(xdr, 4); if (!p) goto err_eop; if (net_read_uint32(p)) { ret = 0; goto out; } break; } /* skip over fileid */ p = xdr_inline_decode(xdr, 8); if (!p) goto err_eop; ret = decode_filename(xdr, name, &len); if (ret) goto out; dir_emit(ctx, name, len, 0, DT_UNKNOWN); p = xdr_inline_decode(xdr, 8); if (!p) goto err_eop; ndir->cookie = ntoh64(net_read_uint64(p)); } free(buf); } ret = 0; out: free(ndir->stream.buf); free(ndir); return ret; err_eop: pr_err("Unexpected end of packet\n"); return -EIO; }
CWE-119
1,341
11,898
242698931901695623082584174296893667851
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_lookup_req(struct nfs_priv *npriv, struct nfs_fh *fh, const char *filename, struct inode *inode) { struct nfs_inode *ninode = nfsi(inode); uint32_t data[1024]; uint32_t *p; int len; struct packet *nfs_packet; /* * struct LOOKUP3args { * diropargs3 what; * }; * * struct LOOKUP3resok { * nfs_fh3 object; * post_op_attr obj_attributes; * post_op_attr dir_attributes; * }; * * struct LOOKUP3resfail { * post_op_attr dir_attributes; * }; * * union LOOKUP3res switch (nfsstat3 status) { * case NFS3_OK: * LOOKUP3resok resok; * default: * LOOKUP3resfail resfail; * }; */ p = &(data[0]); p = rpc_add_credentials(p); /* what.dir */ p = nfs_add_fh3(p, fh); /* what.name */ p = nfs_add_filename(p, strlen(filename), filename); len = p - &(data[0]); nfs_packet = rpc_req(npriv, PROG_NFS, NFSPROC3_LOOKUP, data, len); if (IS_ERR(nfs_packet)) return PTR_ERR(nfs_packet); p = (void *)nfs_packet->data + sizeof(struct rpc_reply) + 4; ninode->fh.size = ntoh32(net_read_uint32(p++)); if (ninode->fh.size > NFS3_FHSIZE) { debug("%s: file handle too big: %u\n", __func__, ninode->fh.size); return -EIO; } memcpy(ninode->fh.data, p, ninode->fh.size); p += DIV_ROUND_UP(ninode->fh.size, 4); nfs_read_post_op_attr(p, inode); free(nfs_packet); return 0; }
CWE-119
1,342
11,899
245532982720186297002735029166009269514
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_mount_req(struct nfs_priv *npriv) { uint32_t data[1024]; uint32_t *p; int len; int pathlen; struct packet *nfs_packet; pathlen = strlen(npriv->path); debug("%s: %s\n", __func__, npriv->path); p = &(data[0]); p = rpc_add_credentials(p); *p++ = hton32(pathlen); if (pathlen & 3) *(p + pathlen / 4) = 0; memcpy (p, npriv->path, pathlen); p += (pathlen + 3) / 4; len = p - &(data[0]); nfs_packet = rpc_req(npriv, PROG_MOUNT, MOUNT_ADDENTRY, data, len); if (IS_ERR(nfs_packet)) return PTR_ERR(nfs_packet); p = (void *)nfs_packet->data + sizeof(struct rpc_reply) + 4; npriv->rootfh.size = ntoh32(net_read_uint32(p++)); if (npriv->rootfh.size > NFS3_FHSIZE) { printf("%s: file handle too big: %lu\n", __func__, (unsigned long)npriv->rootfh.size); free(nfs_packet); return -EIO; } memcpy(npriv->rootfh.data, p, npriv->rootfh.size); free(nfs_packet); return 0; }
CWE-119
1,344
11,900
331875816005275678387184302896193500752
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_open(struct device_d *dev, FILE *file, const char *filename) { struct inode *inode = file->f_inode; struct nfs_inode *ninode = nfsi(inode); struct nfs_priv *npriv = ninode->npriv; struct file_priv *priv; priv = xzalloc(sizeof(*priv)); priv->fh = ninode->fh; priv->npriv = npriv; file->priv = priv; file->size = inode->i_size; priv->fifo = kfifo_alloc(1024); if (!priv->fifo) { free(priv); return -ENOMEM; } return 0; }
CWE-119
1,345
11,901
161059901228751386361185035289830586816
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_probe(struct device_d *dev) { struct fs_device_d *fsdev = dev_to_fs_device(dev); struct nfs_priv *npriv = xzalloc(sizeof(struct nfs_priv)); struct super_block *sb = &fsdev->sb; char *tmp = xstrdup(fsdev->backingstore); char *path; struct inode *inode; int ret; dev->priv = npriv; debug("nfs: mount: %s\n", fsdev->backingstore); path = strchr(tmp, ':'); if (!path) { ret = -EINVAL; goto err; } *path = 0; npriv->path = xstrdup(path + 1); ret = resolv(tmp, &npriv->server); if (ret) { printf("cannot resolve \"%s\": %s\n", tmp, strerror(-ret)); goto err1; } debug("nfs: server: %s path: %s\n", tmp, npriv->path); npriv->con = net_udp_new(npriv->server, SUNRPC_PORT, nfs_handler, npriv); if (IS_ERR(npriv->con)) { ret = PTR_ERR(npriv->con); goto err1; } /* Need a priviliged source port */ net_udp_bind(npriv->con, 1000); parseopt_hu(fsdev->options, "mountport", &npriv->mount_port); if (!npriv->mount_port) { ret = rpc_lookup_req(npriv, PROG_MOUNT, 3); if (ret < 0) { printf("lookup mount port failed with %d\n", ret); goto err2; } npriv->mount_port = ret; } else { npriv->manual_mount_port = 1; } debug("mount port: %hu\n", npriv->mount_port); parseopt_hu(fsdev->options, "port", &npriv->nfs_port); if (!npriv->nfs_port) { ret = rpc_lookup_req(npriv, PROG_NFS, 3); if (ret < 0) { printf("lookup nfs port failed with %d\n", ret); goto err2; } npriv->nfs_port = ret; } else { npriv->manual_nfs_port = 1; } debug("nfs port: %d\n", npriv->nfs_port); ret = nfs_mount_req(npriv); if (ret) { printf("mounting failed with %d\n", ret); goto err2; } nfs_set_rootarg(npriv, fsdev); free(tmp); sb->s_op = &nfs_ops; inode = new_inode(sb); nfs_set_fh(inode, &npriv->rootfh); nfs_init_inode(npriv, inode, S_IFDIR); sb->s_root = d_make_root(inode); return 0; err2: net_unregister(npriv->con); err1: free(npriv->path); err: free(tmp); free(npriv); return ret; }
CWE-119
1,346
11,902
80684074025251593598359572858662412362
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_read(struct device_d *dev, FILE *file, void *buf, size_t insize) { struct file_priv *priv = file->priv; if (insize > 1024) insize = 1024; if (insize && !kfifo_len(priv->fifo)) { int ret = nfs_read_req(priv, file->pos, insize); if (ret) return ret; } return kfifo_get(priv->fifo, buf, insize); }
CWE-119
1,347
11,903
198562974233192997446765317098477946706
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_read_req(struct file_priv *priv, uint64_t offset, uint32_t readlen) { uint32_t data[1024]; uint32_t *p; int len; struct packet *nfs_packet; uint32_t rlen, eof; /* * struct READ3args { * nfs_fh3 file; * offset3 offset; * count3 count; * }; * * struct READ3resok { * post_op_attr file_attributes; * count3 count; * bool eof; * opaque data<>; * }; * * struct READ3resfail { * post_op_attr file_attributes; * }; * * union READ3res switch (nfsstat3 status) { * case NFS3_OK: * READ3resok resok; * default: * READ3resfail resfail; * }; */ p = &(data[0]); p = rpc_add_credentials(p); p = nfs_add_fh3(p, &priv->fh); p = nfs_add_uint64(p, offset); p = nfs_add_uint32(p, readlen); len = p - &(data[0]); nfs_packet = rpc_req(priv->npriv, PROG_NFS, NFSPROC3_READ, data, len); if (IS_ERR(nfs_packet)) return PTR_ERR(nfs_packet); p = (void *)nfs_packet->data + sizeof(struct rpc_reply) + 4; p = nfs_read_post_op_attr(p, NULL); rlen = ntoh32(net_read_uint32(p)); /* skip over count */ p += 1; eof = ntoh32(net_read_uint32(p)); /* * skip over eof and count embedded in the representation of data * assuming it equals rlen above. */ p += 2; if (readlen && !rlen && !eof) { free(nfs_packet); return -EIO; } kfifo_put(priv->fifo, (char *)p, rlen); free(nfs_packet); return 0; }
CWE-119
1,349
11,904
134039819511446535451790351328852292850
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static void *nfs_readdirattr_req(struct nfs_priv *npriv, struct nfs_dir *dir) { uint32_t data[1024]; uint32_t *p; int len; struct packet *nfs_packet; void *buf; /* * struct READDIR3args { * nfs_fh3 dir; * cookie3 cookie; * cookieverf3 cookieverf; * count3 count; * }; * * struct entry3 { * fileid3 fileid; * filename3 name; * cookie3 cookie; * entry3 *nextentry; * }; * * struct dirlist3 { * entry3 *entries; * bool eof; * }; * * struct READDIR3resok { * post_op_attr dir_attributes; * cookieverf3 cookieverf; * dirlist3 reply; * }; * * struct READDIR3resfail { * post_op_attr dir_attributes; * }; * * union READDIR3res switch (nfsstat3 status) { * case NFS3_OK: * READDIR3resok resok; * default: * READDIR3resfail resfail; * }; */ p = &(data[0]); p = rpc_add_credentials(p); p = nfs_add_fh3(p, &dir->fh); p = nfs_add_uint64(p, dir->cookie); memcpy(p, dir->cookieverf, NFS3_COOKIEVERFSIZE); p += NFS3_COOKIEVERFSIZE / 4; p = nfs_add_uint32(p, 1024); /* count */ nfs_packet = rpc_req(npriv, PROG_NFS, NFSPROC3_READDIR, data, p - data); if (IS_ERR(nfs_packet)) return NULL; p = (void *)nfs_packet->data + sizeof(struct rpc_reply) + 4; p = nfs_read_post_op_attr(p, NULL); /* update cookieverf */ memcpy(dir->cookieverf, p, NFS3_COOKIEVERFSIZE); p += NFS3_COOKIEVERFSIZE / 4; len = (void *)nfs_packet->data + nfs_packet->len - (void *)p; if (!len) { printf("%s: huh, no payload left\n", __func__); free(nfs_packet); return NULL; } buf = xzalloc(len); memcpy(buf, p, len); free(nfs_packet); xdr_init(&dir->stream, buf, len); /* now xdr points to dirlist3 res.resok.reply */ return buf; }
CWE-119
1,350
11,905
33111516012839588635053205608118121564
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static void nfs_remove(struct device_d *dev) { struct nfs_priv *npriv = dev->priv; nfs_umount_req(npriv); net_unregister(npriv->con); free(npriv->path); free(npriv); }
CWE-119
1,351
11,906
284031430208650239924671872470904419249
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static void nfs_set_fh(struct inode *inode, struct nfs_fh *fh) { struct nfs_inode *ninode = nfsi(inode); ninode->fh = *fh; }
CWE-119
1,352
11,907
58378847057308957811808465566542740977
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device_d *fsdev) { char *str, *tmp; const char *bootargs; str = basprintf("root=/dev/nfs nfsroot=%pI4:%s%s%s", &npriv->server, npriv->path, rootnfsopts[0] ? "," : "", rootnfsopts); /* forward specific mount options on demand */ if (npriv->manual_nfs_port == 1) { tmp = basprintf("%s,port=%hu", str, npriv->nfs_port); free(str); str = tmp; } if (npriv->manual_mount_port == 1) { tmp = basprintf("%s,mountport=%hu", str, npriv->mount_port); free(str); str = tmp; } bootargs = dev_get_param(&npriv->con->edev->dev, "linux.bootargs"); if (bootargs) { tmp = basprintf("%s %s", str, bootargs); free(str); str = tmp; } fsdev_set_linux_rootarg(fsdev, str); free(str); }
CWE-119
1,353
11,908
76552307264996822044175939881575562560
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_truncate(struct device_d *dev, FILE *f, loff_t size) { return -ENOSYS; }
CWE-119
1,354
11,909
167515336626266229442703983073035349747
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static void nfs_umount_req(struct nfs_priv *npriv) { uint32_t data[1024]; uint32_t *p; int len; int pathlen; struct packet *nfs_packet; pathlen = strlen(npriv->path); p = &(data[0]); p = rpc_add_credentials(p); p = nfs_add_filename(p, pathlen, npriv->path); len = p - &(data[0]); nfs_packet = rpc_req(npriv, PROG_MOUNT, MOUNT_UMOUNT, data, len); if (!IS_ERR(nfs_packet)) free(nfs_packet); }
CWE-119
1,355
11,910
82748209556622680467512421734320893749
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int nfs_write(struct device_d *_dev, FILE *file, const void *inbuf, size_t insize) { return -ENOSYS; }
CWE-119
1,356
11,911
279952202357027392072499226071049100612
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static inline struct nfs_inode *nfsi(struct inode *inode) { return container_of(inode, struct nfs_inode, inode); }
CWE-119
1,357
11,912
121329833098091289688791892721060078025
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static uint32_t *rpc_add_credentials(uint32_t *p) { /* * *BSD refuses AUTH_NONE, so use AUTH_UNIX. An empty hostname is OK for * both Linux and *BSD. */ /* Provide an AUTH_UNIX credential. */ *p++ = hton32(1); /* AUTH_UNIX */ *p++ = hton32(20); /* auth length: 20 + strlen(hostname) */ *p++ = hton32(0); /* stamp */ *p++ = hton32(0); /* hostname string length */ /* memcpy(p, "", 0); p += 0; <- empty host name */ *p++ = 0; /* uid */ *p++ = 0; /* gid */ *p++ = 0; /* auxiliary gid list */ /* Provide an AUTH_NONE verifier. */ *p++ = 0; /* AUTH_NONE */ *p++ = 0; /* auth length */ return p; }
CWE-119
1,358
11,913
246397334779844021132260455120921214111
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int rpc_check_reply(struct packet *pkt, int rpc_prog, uint32_t rpc_id, int *nfserr) { uint32_t *data; struct rpc_reply rpc; *nfserr = 0; if (!pkt) return -EAGAIN; memcpy(&rpc, pkt->data, sizeof(rpc)); if (ntoh32(rpc.id) != rpc_id) { if (rpc_id - ntoh32(rpc.id) == 1) /* stale packet, wait a bit longer */ return 0; return -EINVAL; } if (rpc.rstatus || rpc.verifier || rpc.astatus ) { return -EINVAL; } if (rpc_prog != PROG_NFS) return 0; data = (uint32_t *)(pkt->data + sizeof(struct rpc_reply)); *nfserr = ntoh32(net_read_uint32(data)); *nfserr = -*nfserr; debug("%s: state: %d, err %d\n", __func__, nfs_state, *nfserr); return 0; }
CWE-119
1,359
11,914
68859461336354027304761534161344527264
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static int rpc_lookup_req(struct nfs_priv *npriv, uint32_t prog, uint32_t ver) { uint32_t data[16]; struct packet *nfs_packet; uint32_t port; data[0] = 0; data[1] = 0; /* auth credential */ data[2] = 0; data[3] = 0; /* auth verifier */ data[4] = hton32(prog); data[5] = hton32(ver); data[6] = hton32(17); /* IP_UDP */ data[7] = 0; nfs_packet = rpc_req(npriv, PROG_PORTMAP, PORTMAP_GETPORT, data, 8); if (IS_ERR(nfs_packet)) return PTR_ERR(nfs_packet); port = ntoh32(net_read_uint32(nfs_packet->data + sizeof(struct rpc_reply))); free(nfs_packet); return port; }
CWE-119
1,360
11,915
326798859938033462780802655690518061757
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static struct packet *rpc_req(struct nfs_priv *npriv, int rpc_prog, int rpc_proc, uint32_t *data, int datalen) { struct rpc_call pkt; unsigned short dport; int ret; unsigned char *payload = net_udp_get_payload(npriv->con); int nfserr; int tries = 0; npriv->rpc_id++; pkt.id = hton32(npriv->rpc_id); pkt.type = hton32(MSG_CALL); pkt.rpcvers = hton32(2); /* use RPC version 2 */ pkt.prog = hton32(rpc_prog); pkt.proc = hton32(rpc_proc); debug("%s: prog: %d, proc: %d\n", __func__, rpc_prog, rpc_proc); if (rpc_prog == PROG_PORTMAP) { dport = SUNRPC_PORT; pkt.vers = hton32(2); } else if (rpc_prog == PROG_MOUNT) { dport = npriv->mount_port; pkt.vers = hton32(3); } else { dport = npriv->nfs_port; pkt.vers = hton32(3); } memcpy(payload, &pkt, sizeof(pkt)); memcpy(payload + sizeof(pkt), data, datalen * sizeof(uint32_t)); npriv->con->udp->uh_dport = hton16(dport); nfs_timer_start = get_time_ns(); again: ret = net_udp_send(npriv->con, sizeof(pkt) + datalen * sizeof(uint32_t)); if (ret) { if (is_timeout(nfs_timer_start, NFS_TIMEOUT)) { tries++; if (tries == NFS_MAX_RESEND) return ERR_PTR(-ETIMEDOUT); } goto again; } nfs_timer_start = get_time_ns(); nfs_state = STATE_START; while (nfs_state != STATE_DONE) { if (ctrlc()) return ERR_PTR(-EINTR); net_poll(); if (is_timeout(nfs_timer_start, NFS_TIMEOUT)) { tries++; if (tries == NFS_MAX_RESEND) return ERR_PTR(-ETIMEDOUT); goto again; } ret = rpc_check_reply(npriv->nfs_packet, rpc_prog, npriv->rpc_id, &nfserr); if (!ret) { if (rpc_prog == PROG_NFS && nfserr) { free(npriv->nfs_packet); return ERR_PTR(nfserr); } else { return npriv->nfs_packet; } } } return npriv->nfs_packet; }
CWE-119
1,361
11,916
71434467066008011687284125202914946067
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static void xdr_init(struct xdr_stream *stream, void *buf, int len) { stream->p = stream->buf = buf; stream->end = stream->buf + len; }
CWE-119
1,362
11,917
62474850152458437422505524756949369434
null
null
null
pengutronix
574ce994016107ad8ab0f845a785f28d7eaa5208
0
static __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes) { __be32 *p; if (nbytes == 0) return xdr->p; if (xdr->p == xdr->end) return NULL; p = __xdr_inline_decode(xdr, nbytes); return p; }
CWE-119
1,363
11,918
214492938239788450247321577989202410540
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static void nfs_lookup_req(char *fname) { uint32_t data[1024]; uint32_t *p; int len; int fnamelen; fnamelen = strlen (fname); p = &(data[0]); p = rpc_add_credentials(p); memcpy (p, dirfh, NFS_FHSIZE); p += (NFS_FHSIZE / 4); *p++ = htonl(fnamelen); if (fnamelen & 3) *(p + fnamelen / 4) = 0; memcpy (p, fname, fnamelen); p += (fnamelen + 3) / 4; len = p - &(data[0]); rpc_req(PROG_NFS, NFS_LOOKUP, data, len); }
CWE-119
1,365
11,919
229388027153035261972463074740795604971
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static int nfs_mount_reply(unsigned char *pkt, unsigned len) { int ret; ret = rpc_check_reply(pkt, 1); if (ret) return ret; memcpy(dirfh, pkt + sizeof(struct rpc_reply) + 4, NFS_FHSIZE); return 0; }
CWE-119
1,366
11,920
208931578812008916906119311759857189199
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static void nfs_mount_req(char *path) { uint32_t data[1024]; uint32_t *p; int len; int pathlen; pathlen = strlen (path); p = &(data[0]); p = rpc_add_credentials(p); *p++ = htonl(pathlen); if (pathlen & 3) *(p + pathlen / 4) = 0; memcpy (p, path, pathlen); p += (pathlen + 3) / 4; len = p - &(data[0]); rpc_req(PROG_MOUNT, MOUNT_ADDENTRY, data, len); }
CWE-119
1,367
11,921
63151979744923879039030442190495092720
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static void nfs_read_req(int offset, int readlen) { uint32_t data[1024]; uint32_t *p; int len; p = &(data[0]); p = rpc_add_credentials(p); memcpy (p, filefh, NFS_FHSIZE); p += (NFS_FHSIZE / 4); *p++ = htonl(offset); *p++ = htonl(readlen); *p++ = 0; len = p - &(data[0]); rpc_req(PROG_NFS, NFS_READ, data, len); }
CWE-119
1,368
11,922
139608681964795405958695205077999593118
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static void nfs_readlink_req(void) { uint32_t data[1024]; uint32_t *p; int len; p = &(data[0]); p = rpc_add_credentials(p); memcpy (p, filefh, NFS_FHSIZE); p += (NFS_FHSIZE / 4); len = p - &(data[0]); rpc_req(PROG_NFS, NFS_READLINK, data, len); }
CWE-119
1,369
11,923
184989573467561902168669006749514850720
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static void nfs_send(void) { debug("%s\n", __func__); switch (nfs_state) { case STATE_PRCLOOKUP_PROG_MOUNT_REQ: rpc_lookup_req(PROG_MOUNT, 1); break; case STATE_PRCLOOKUP_PROG_NFS_REQ: rpc_lookup_req(PROG_NFS, 2); break; case STATE_MOUNT_REQ: nfs_mount_req(nfs_path); break; case STATE_UMOUNT_REQ: nfs_umountall_req(); break; case STATE_LOOKUP_REQ: nfs_lookup_req(nfs_filename); break; case STATE_READ_REQ: nfs_read_req(nfs_offset, NFS_READ_SIZE); break; case STATE_READLINK_REQ: nfs_readlink_req(); break; } nfs_timer_start = get_time_ns(); }
CWE-119
1,370
11,924
96255136318655953585076532414295442956
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static int nfs_umountall_reply(unsigned char *pkt, unsigned len) { int ret; ret = rpc_check_reply(pkt, 0); if (ret) return ret; memset(dirfh, 0, sizeof(dirfh)); return 0; }
CWE-119
1,371
11,925
117262003008172292446283966903984092547
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static void nfs_umountall_req(void) { uint32_t data[1024]; uint32_t *p; int len; if (nfs_server_mount_port < 0) /* Nothing mounted, nothing to umount */ return; p = &(data[0]); p = rpc_add_credentials(p); len = p - &(data[0]); rpc_req(PROG_MOUNT, MOUNT_UMOUNTALL, data, len); }
CWE-119
1,372
11,926
159565096898999343674376501999936270512
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static uint32_t *rpc_add_credentials(uint32_t *p) { int hl; int hostnamelen = 0; /* Here's the executive summary on authentication requirements of the * various NFS server implementations: Linux accepts both AUTH_NONE * and AUTH_UNIX authentication (also accepts an empty hostname field * in the AUTH_UNIX scheme). *BSD refuses AUTH_NONE, but accepts * AUTH_UNIX (also accepts an empty hostname field in the AUTH_UNIX * scheme). To be safe, use AUTH_UNIX and pass the hostname if we have * it (if the BOOTP/DHCP reply didn't give one, just use an empty * hostname). */ hl = (hostnamelen + 3) & ~3; /* Provide an AUTH_UNIX credential. */ *p++ = htonl(1); /* AUTH_UNIX */ *p++ = htonl(hl+20); /* auth length */ *p++ = htonl(0); /* stamp */ *p++ = htonl(hostnamelen); /* hostname string */ if (hostnamelen & 3) *(p + hostnamelen / 4) = 0; /* add zero padding */ /* memcpy(p, hostname, hostnamelen); */ /* empty hostname */ p += hl / 4; *p++ = 0; /* uid */ *p++ = 0; /* gid */ *p++ = 0; /* auxiliary gid list */ /* Provide an AUTH_NONE verifier. */ *p++ = 0; /* AUTH_NONE */ *p++ = 0; /* auth length */ return p; }
CWE-119
1,373
11,927
5186934943151252003163418596112838206
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static int rpc_lookup_reply(int prog, unsigned char *pkt, unsigned len) { uint32_t port; int ret; ret = rpc_check_reply(pkt, 0); if (ret) return ret; port = net_read_uint32((uint32_t *)(pkt + sizeof(struct rpc_reply))); switch (prog) { case PROG_MOUNT: nfs_server_mount_port = ntohl(port); break; case PROG_NFS: nfs_server_nfs_port = ntohl(port); break; } return 0; }
CWE-119
1,375
11,928
30532075050965067303504009831667027024
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static void rpc_lookup_req(int prog, int ver) { uint32_t data[16]; data[0] = 0; data[1] = 0; /* auth credential */ data[2] = 0; data[3] = 0; /* auth verifier */ data[4] = htonl(prog); data[5] = htonl(ver); data[6] = htonl(17); /* IP_UDP */ data[7] = 0; rpc_req(PROG_PORTMAP, PORTMAP_GETPORT, data, 8); }
CWE-119
1,376
11,929
46118774964237511825853971515276244109
null
null
null
pengutronix
84986ca024462058574432b5483f4bf9136c538d
0
static int rpc_req(int rpc_prog, int rpc_proc, uint32_t *data, int datalen) { struct rpc_call pkt; unsigned long id; int sport; int ret; unsigned char *payload = net_udp_get_payload(nfs_con); id = ++rpc_id; pkt.id = htonl(id); pkt.type = htonl(MSG_CALL); pkt.rpcvers = htonl(2); /* use RPC version 2 */ pkt.prog = htonl(rpc_prog); pkt.vers = htonl(2); /* portmapper is version 2 */ pkt.proc = htonl(rpc_proc); memcpy(payload, &pkt, sizeof(pkt)); memcpy(payload + sizeof(pkt), data, datalen * sizeof(uint32_t)); if (rpc_prog == PROG_PORTMAP) sport = SUNRPC_PORT; else if (rpc_prog == PROG_MOUNT) sport = nfs_server_mount_port; else sport = nfs_server_nfs_port; nfs_con->udp->uh_dport = htons(sport); ret = net_udp_send(nfs_con, sizeof(pkt) + datalen * sizeof(uint32_t)); return ret; }
CWE-119
1,377
11,930
292489349805107142697977164235499655206
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
static void invalidate_stack_devices(i_ctx_t *i_ctx_p) { os_ptr op = osbot; while (op != ostop) { if (r_has_type(op, t_device)) op->value.pdevice = 0; op++; } }
1,542
11,998
229119428316359634496773717859445161488
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zcopydevice2(i_ctx_t *i_ctx_p) { os_ptr op = osp; gx_device *new_dev; int code; check_read_type(op[-1], t_device); check_type(*op, t_boolean); if (op[-1].value.pdevice == NULL) /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */ return_error(gs_error_undefined); code = gs_copydevice2(&new_dev, op[-1].value.pdevice, op->value.boolval, imemory); if (code < 0) return code; new_dev->memory = imemory; make_tav(op - 1, t_device, icurrent_space | a_all, pdevice, new_dev); pop(1); return 0; }
1,543
11,999
114567689831721005431515180840017535978
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zcurrentdevice(i_ctx_t *i_ctx_p) { os_ptr op = osp; gx_device *dev = gs_currentdevice(igs); gs_ref_memory_t *mem = (gs_ref_memory_t *) dev->memory; push(1); make_tav(op, t_device, (mem == 0 ? avm_foreign : imemory_space(mem)) | a_all, pdevice, dev); return 0; }
1,544
12,000
49910706268464586168737555335283383648
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zcurrentoutputdevice(i_ctx_t *i_ctx_p) { os_ptr op = osp; gx_device *odev = NULL, *dev = gs_currentdevice(igs); gs_ref_memory_t *mem = (gs_ref_memory_t *) dev->memory; int code = dev_proc(dev, dev_spec_op)(dev, gxdso_current_output_device, (void *)&odev, 0); if (code < 0) return code; push(1); make_tav(op, t_device, (mem == 0 ? avm_foreign : imemory_space(mem)) | a_all, pdevice, odev); return 0; }
1,545
12,001
328120875030526282779163741599950313923
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zdevicename(i_ctx_t *i_ctx_p) { os_ptr op = osp; const char *dname; check_read_type(*op, t_device); if (op->value.pdevice == NULL) /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */ return_error(gs_error_undefined); dname = op->value.pdevice->dname; make_const_string(op, avm_foreign | a_readonly, strlen(dname), (const byte *)dname); return 0; }
1,546
12,002
146202998067799874591718731069900965692
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zdoneshowpage(i_ctx_t *i_ctx_p) { gx_device *dev = gs_currentdevice(igs); gx_device *tdev = (*dev_proc(dev, get_page_device)) (dev); if (tdev != 0) tdev->ShowpageCount++; return 0; }
1,547
12,003
72344417695819959771257045737850078209
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zflushpage(i_ctx_t *i_ctx_p) { return gs_flushpage(igs); }
1,548
12,004
60375934764057282836122906437816039978
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zget_device_params(i_ctx_t *i_ctx_p, bool is_hardware) { os_ptr op = osp; ref rkeys; gx_device *dev; stack_param_list list; int code; ref *pmark; check_read_type(op[-1], t_device); if(!r_has_type(op, t_null)) { check_type(*op, t_dictionary); } rkeys = *op; dev = op[-1].value.pdevice; if (op[-1].value.pdevice == NULL) /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */ return_error(gs_error_undefined); pop(1); stack_param_list_write(&list, &o_stack, &rkeys, iimemory); code = gs_get_device_or_hardware_params(dev, (gs_param_list *) & list, is_hardware); if (code < 0) { /* We have to put back the top argument. */ if (list.count > 0) ref_stack_pop(&o_stack, list.count * 2 - 1); else ref_stack_push(&o_stack, 1); *osp = rkeys; return code; } pmark = ref_stack_index(&o_stack, list.count * 2); make_mark(pmark); return 0; }
1,549
12,005
138932037664906522091402995637620456115
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zgetbitsrect(i_ctx_t *i_ctx_p) { /* * alpha? is 0 for no alpha, -1 for alpha first, 1 for alpha last. * std_depth is null for native pixels, depth/component for * standard color space. */ os_ptr op = osp; gx_device *dev; gs_int_rect rect; gs_get_bits_params_t params; int w, h; gs_get_bits_options_t options = GB_ALIGN_ANY | GB_RETURN_COPY | GB_OFFSET_0 | GB_RASTER_STANDARD | GB_PACKING_CHUNKY; int depth; uint raster; int num_rows; int code; check_read_type(op[-7], t_device); dev = op[-7].value.pdevice; if (dev == NULL) /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */ return_error(gs_error_undefined); check_int_leu(op[-6], dev->width); rect.p.x = op[-6].value.intval; check_int_leu(op[-5], dev->height); rect.p.y = op[-5].value.intval; check_int_leu(op[-4], dev->width); w = op[-4].value.intval; check_int_leu(op[-3], dev->height); h = op[-3].value.intval; check_type(op[-2], t_integer); /* * We use if/else rather than switch because the value is long, * which is not supported as a switch value in pre-ANSI C. */ if (op[-2].value.intval == -1) options |= GB_ALPHA_FIRST; else if (op[-2].value.intval == 0) options |= GB_ALPHA_NONE; else if (op[-2].value.intval == 1) options |= GB_ALPHA_LAST; else return_error(gs_error_rangecheck); if (r_has_type(op - 1, t_null)) { options |= GB_COLORS_NATIVE; depth = dev->color_info.depth; } else { static const gs_get_bits_options_t depths[17] = { 0, GB_DEPTH_1, GB_DEPTH_2, 0, GB_DEPTH_4, 0, 0, 0, GB_DEPTH_8, 0, 0, 0, GB_DEPTH_12, 0, 0, 0, GB_DEPTH_16 }; gs_get_bits_options_t depth_option; int std_depth; check_int_leu(op[-1], 16); std_depth = (int)op[-1].value.intval; depth_option = depths[std_depth]; if (depth_option == 0) return_error(gs_error_rangecheck); options |= depth_option | GB_COLORS_NATIVE; depth = (dev->color_info.num_components + (options & GB_ALPHA_NONE ? 0 : 1)) * std_depth; } if (w == 0) return_error(gs_error_rangecheck); raster = (w * depth + 7) >> 3; check_write_type(*op, t_string); num_rows = r_size(op) / raster; h = min(h, num_rows); if (h == 0) return_error(gs_error_rangecheck); rect.q.x = rect.p.x + w; rect.q.y = rect.p.y + h; params.options = options; params.data[0] = op->value.bytes; code = (*dev_proc(dev, get_bits_rectangle))(dev, &rect, &params, NULL); if (code < 0) return code; make_int(op - 7, h); op[-6] = *op; r_set_size(op - 6, h * raster); pop(6); return 0; }
1,550
12,006
251946344785498924485286388446356948147
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zgetdefaultdevice(i_ctx_t *i_ctx_p) { os_ptr op = osp; const gx_device *dev; dev = gs_getdefaultlibdevice(imemory); if (dev == 0) /* couldn't find a default device */ return_error(gs_error_unknownerror); push(1); make_tav(op, t_device, avm_foreign | a_readonly, pdevice, (gx_device *) dev); return 0; }
1,551
12,007
82807302927185642401889806902900260273
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zgetdevice(i_ctx_t *i_ctx_p) { os_ptr op = osp; const gx_device *dev; check_type(*op, t_integer); if (op->value.intval != (int)(op->value.intval)) return_error(gs_error_rangecheck); /* won't fit in an int */ dev = gs_getdevice((int)(op->value.intval)); if (dev == 0) /* index out of range */ return_error(gs_error_rangecheck); /* Device prototypes are read-only; */ /* the cast is logically unnecessary. */ make_tav(op, t_device, avm_foreign | a_readonly, pdevice, (gx_device *) dev); return 0; }
1,552
12,008
256419655008101125501727035110401128551
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zgetdeviceparams(i_ctx_t *i_ctx_p) { return zget_device_params(i_ctx_p, false); }
1,553
12,009
93902633746946761579919664625472487710
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zgethardwareparams(i_ctx_t *i_ctx_p) { return zget_device_params(i_ctx_p, true); }
1,554
12,010
325455651075364464828969668486418976703
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zmakewordimagedevice(i_ctx_t *i_ctx_p) { os_ptr op = osp; os_ptr op1 = op - 1; gs_matrix imat; gx_device *new_dev; const byte *colors; int colors_size; int code; check_int_leu(op[-3], max_uint >> 1); /* width */ check_int_leu(op[-2], max_uint >> 1); /* height */ check_type(*op, t_boolean); if (r_has_type(op1, t_null)) { /* true color */ colors = 0; colors_size = -24; /* 24-bit true color */ } else if (r_has_type(op1, t_integer)) { /* * We use if/else rather than switch because the value is long, * which is not supported as a switch value in pre-ANSI C. */ if (op1->value.intval != 16 && op1->value.intval != 24 && op1->value.intval != 32 ) return_error(gs_error_rangecheck); colors = 0; colors_size = -op1->value.intval; } else { check_type(*op1, t_string); /* palette */ if (r_size(op1) > 3 * 256) return_error(gs_error_rangecheck); colors = op1->value.bytes; colors_size = r_size(op1); } if ((code = read_matrix(imemory, op - 4, &imat)) < 0) return code; /* Everything OK, create device */ code = gs_makewordimagedevice(&new_dev, &imat, (int)op[-3].value.intval, (int)op[-2].value.intval, colors, colors_size, op->value.boolval, true, imemory); if (code == 0) { new_dev->memory = imemory; make_tav(op - 4, t_device, imemory_space(iimemory) | a_all, pdevice, new_dev); pop(4); } return code; }
1,555
12,011
115057742140335474750814397481232144294
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
znulldevice(i_ctx_t *i_ctx_p) { int code = gs_nulldevice(igs); invalidate_stack_devices(i_ctx_p); clear_pagedevice(istate); return code; }
1,556
12,012
58944587979686033311977064352496342381
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zputdeviceparams(i_ctx_t *i_ctx_p) { uint count = ref_stack_counttomark(&o_stack); ref *prequire_all; ref *ppolicy; ref *pdev; gx_device *dev; stack_param_list list; int code; int old_width, old_height; int i, dest; if (count == 0) return_error(gs_error_unmatchedmark); prequire_all = ref_stack_index(&o_stack, count); ppolicy = ref_stack_index(&o_stack, count + 1); pdev = ref_stack_index(&o_stack, count + 2); if (pdev == 0) return_error(gs_error_stackunderflow); check_type_only(*prequire_all, t_boolean); check_write_type_only(*pdev, t_device); dev = pdev->value.pdevice; if (dev == NULL) /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */ return_error(gs_error_undefined); code = stack_param_list_read(&list, &o_stack, 0, ppolicy, prequire_all->value.boolval, iimemory); if (code < 0) return code; old_width = dev->width; old_height = dev->height; code = gs_putdeviceparams(dev, (gs_param_list *) & list); /* Check for names that were undefined or caused errors. */ for (dest = count - 2, i = 0; i < count >> 1; i++) if (list.results[i] < 0) { *ref_stack_index(&o_stack, dest) = *ref_stack_index(&o_stack, count - (i << 1) - 2); gs_errorname(i_ctx_p, list.results[i], ref_stack_index(&o_stack, dest - 1)); dest -= 2; } iparam_list_release(&list); if (code < 0) { /* There were errors reported. */ ref_stack_pop(&o_stack, dest + 1); return (code == gs_error_Fatal) ? code : 0; /* cannot continue from Fatal */ } if (code > 0 || (code == 0 && (dev->width != old_width || dev->height != old_height))) { /* * The device was open and is now closed, or its dimensions have * changed. If it was the current device, call setdevice to * reinstall it and erase the page. */ /****** DOESN'T FIND ALL THE GSTATES THAT REFERENCE THE DEVICE. ******/ if (gs_currentdevice(igs) == dev) { bool was_open = dev->is_open; code = gs_setdevice_no_erase(igs, dev); /* If the device wasn't closed, setdevice won't erase the page. */ if (was_open && code >= 0) code = 1; } } if (code < 0) return code; ref_stack_pop(&o_stack, count + 1); make_bool(osp, code); clear_pagedevice(istate); return 0; }
1,558
12,013
305631736188005015674838171488046236720
null
null
null
ghostscript
661e8d8fb8248c38d67958beda32f3a5876d0c3f
0
zspec_op(i_ctx_t *i_ctx_p) { os_ptr op = osp; gx_device *dev = gs_currentdevice(igs); int i, nprocs = sizeof(spec_op_defs) / sizeof(spec_op_t), code, proc = -1; ref opname, nref, namestr; char *data; /* At the very minimum we need a name object telling us which sepc_op to perform */ check_op(1); if (!r_has_type(op, t_name)) return_error(gs_error_typecheck); ref_assign(&opname, op); /* Find the relevant spec_op name */ for (i=0;i<nprocs;i++) { code = names_ref(imemory->gs_lib_ctx->gs_name_table, (const byte *)spec_op_defs[i].name, strlen(spec_op_defs[i].name), &nref, 0); if (code < 0) return code; if (name_eq(&opname, &nref)) { proc = i; break; } } if (proc < 0) return_error(gs_error_undefined); pop(1); /* We don't need the name of the spec_op any more */ op = osp; switch(proc) { case 0: { stack_param_list list; dev_param_req_t request; ref rkeys; /* Get a single device parameter, we should be supplied with * the name of the paramter, as a name object. */ check_op(1); if (!r_has_type(op, t_name)) return_error(gs_error_typecheck); ref_assign(&opname, op); name_string_ref(imemory, &opname, &namestr); data = (char *)gs_alloc_bytes(imemory, r_size(&namestr) + 1, "temporary special_op string"); if (data == 0) return_error(gs_error_VMerror); memset(data, 0x00, r_size(&namestr) + 1); memcpy(data, namestr.value.bytes, r_size(&namestr)); /* Discard the parameter name now, we're done with it */ pop (1); /* Make a null object so that the stack param list won't check for requests */ make_null(&rkeys); stack_param_list_write(&list, &o_stack, &rkeys, iimemory); /* Stuff the data into a structure for passing to the spec_op */ request.Param = data; request.list = &list; code = dev_proc(dev, dev_spec_op)(dev, gxdso_get_dev_param, &request, sizeof(dev_param_req_t)); gs_free_object(imemory, data, "temporary special_op string"); if (code < 0) { if (code == gs_error_undefined) { op = osp; push(1); make_bool(op, 0); } else return_error(code); } else { op = osp; push(1); make_bool(op, 1); } } break; default: /* Belt and braces; it shold not be possible to get here, as the table * containing the names should mirror the entries in this switch. If we * found a name there should be a matching case here. */ return_error(gs_error_undefined); break; } return 0; }
1,559
12,014
301370683910098591347569258357224245830
null
null
null