View | Details | Raw Unified | Return to bug 25476
Collapse All | Expand All

(-)kern_sysctl.c (-10 / +12 lines)
Lines 1217-1222 Link Here
1217
{
1217
{
1218
	int error, name[6];
1218
	int error, name[6];
1219
	size_t size;
1219
	size_t size;
1220
	u_int needed = 0;
1220
1221
1221
	switch (uap->op & 0xff00) {
1222
	switch (uap->op & 0xff00) {
1222
1223
Lines 1280-1295 Link Here
1280
		 * this is pretty crude, but it's just enough for uname()
1281
		 * this is pretty crude, but it's just enough for uname()
1281
		 * from BSDI's 1.x libc to work.
1282
		 * from BSDI's 1.x libc to work.
1282
		 *
1283
		 *
1283
		 * In particular, it doesn't return the same results when
1284
		 * *size gives the size of the buffer before the call, and
1284
		 * the supplied buffer is too small.  BSDI's version apparently
1285
		 * the amount of data copied after a successful call.
1285
		 * will return the amount copied, and set the *size to how
1286
		 * If successful, the return value is the amount of data
1286
		 * much was needed.  The emulation framework here isn't capable
1287
		 * available, which can be larger than *size.
1287
		 * of that, so we just set both to the amount copied.
1288
		 *
1288
		 * BSDI's 2.x product apparently fails with ENOMEM in this
1289
		 * BSDI's 2.x product apparently fails with ENOMEM if *size
1289
		 * scenario.
1290
		 * is too small.
1290
		 */
1291
		 */
1291
1292
1292
		u_int needed;
1293
		u_int left;
1293
		u_int left;
1294
		char *s;
1294
		char *s;
1295
1295
Lines 1312-1324 Link Here
1312
1312
1313
		needed = sizeof(bsdi_si) + (s - bsdi_strings);
1313
		needed = sizeof(bsdi_si) + (s - bsdi_strings);
1314
1314
1315
		if (uap->where == NULL) {
1315
		if ((uap->where == NULL) || (uap->size == NULL)) {
1316
			/* process is asking how much buffer to supply.. */
1316
			/* process is asking how much buffer to supply.. */
1317
			size = needed;
1317
			size = needed;
1318
			error = 0;
1318
			error = 0;
1319
			break;
1319
			break;
1320
		}
1320
		}
1321
1321
1322
		if ((error = copyin(uap->size, &size, sizeof(size))) != 0)
1323
			break;
1322
1324
1323
		/* if too much buffer supplied, trim it down */
1325
		/* if too much buffer supplied, trim it down */
1324
		if (size > needed)
1326
		if (size > needed)
Lines 1344-1350 Link Here
1344
	}
1346
	}
1345
	if (error)
1347
	if (error)
1346
		return (error);
1348
		return (error);
1347
	p->p_retval[0] = size;
1349
	p->p_retval[0] = needed ? needed : size;
1348
	if (uap->size)
1350
	if (uap->size)
1349
		error = copyout((caddr_t)&size, (caddr_t)uap->size,
1351
		error = copyout((caddr_t)&size, (caddr_t)uap->size,
1350
		    sizeof(size));
1352
		    sizeof(size));

Return to bug 25476