expand.c (246288) | expand.c (248980) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1997-2005 5 * Herbert Xu <herbert@gondor.apana.org.au>. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Kenneth Almquist. --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; 38#endif 39#endif /* not lint */ 40#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1997-2005 5 * Herbert Xu <herbert@gondor.apana.org.au>. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Kenneth Almquist. --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; 38#endif 39#endif /* not lint */ 40#include <sys/cdefs.h> |
41__FBSDID("$FreeBSD: head/bin/sh/expand.c 246288 2013-02-03 15:54:57Z jilles $"); | 41__FBSDID("$FreeBSD: head/bin/sh/expand.c 248980 2013-04-01 17:18:22Z jilles $"); |
42 43#include <sys/types.h> 44#include <sys/time.h> 45#include <sys/stat.h> 46#include <dirent.h> 47#include <errno.h> 48#include <inttypes.h> 49#include <limits.h> --- 405 unchanged lines hidden (view full) --- 455 char *p; 456 char *dest = expdest; 457 struct ifsregion saveifs, *savelastp; 458 struct nodelist *saveargbackq; 459 char lastc; 460 int startloc = dest - stackblock(); 461 char const *syntax = quoted? DQSYNTAX : BASESYNTAX; 462 int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR); | 42 43#include <sys/types.h> 44#include <sys/time.h> 45#include <sys/stat.h> 46#include <dirent.h> 47#include <errno.h> 48#include <inttypes.h> 49#include <limits.h> --- 405 unchanged lines hidden (view full) --- 455 char *p; 456 char *dest = expdest; 457 struct ifsregion saveifs, *savelastp; 458 struct nodelist *saveargbackq; 459 char lastc; 460 int startloc = dest - stackblock(); 461 char const *syntax = quoted? DQSYNTAX : BASESYNTAX; 462 int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR); |
463 int nnl; | 463 size_t nnl; |
464 465 INTOFF; 466 saveifs = ifsfirst; 467 savelastp = ifslastp; 468 saveargbackq = argbackq; 469 p = grabstackstr(dest); 470 evalbackcmd(cmd, &in); 471 ungrabstackstr(p, dest); --- 686 unchanged lines hidden (view full) --- 1158 1159/* 1160 * Do metacharacter (i.e. *, ?, [...]) expansion. 1161 */ 1162 1163static void 1164expmeta(char *enddir, char *name) 1165{ | 464 465 INTOFF; 466 saveifs = ifsfirst; 467 savelastp = ifslastp; 468 saveargbackq = argbackq; 469 p = grabstackstr(dest); 470 evalbackcmd(cmd, &in); 471 ungrabstackstr(p, dest); --- 686 unchanged lines hidden (view full) --- 1158 1159/* 1160 * Do metacharacter (i.e. *, ?, [...]) expansion. 1161 */ 1162 1163static void 1164expmeta(char *enddir, char *name) 1165{ |
1166 char *p; 1167 char *q; 1168 char *start; | 1166 const char *p; 1167 const char *q; 1168 const char *start; |
1169 char *endname; 1170 int metaflag; 1171 struct stat statb; 1172 DIR *dirp; 1173 struct dirent *dp; 1174 int atend; 1175 int matchdot; 1176 int esc; --- 47 unchanged lines hidden (view full) --- 1224 break; 1225 if (enddir == expdir_end) 1226 return; 1227 } 1228 if (metaflag == 0 || lstat(expdir, &statb) >= 0) 1229 addfname(expdir); 1230 return; 1231 } | 1169 char *endname; 1170 int metaflag; 1171 struct stat statb; 1172 DIR *dirp; 1173 struct dirent *dp; 1174 int atend; 1175 int matchdot; 1176 int esc; --- 47 unchanged lines hidden (view full) --- 1224 break; 1225 if (enddir == expdir_end) 1226 return; 1227 } 1228 if (metaflag == 0 || lstat(expdir, &statb) >= 0) 1229 addfname(expdir); 1230 return; 1231 } |
1232 endname = p; | 1232 endname = name + (p - name); |
1233 if (start != name) { 1234 p = name; 1235 while (p < start) { 1236 while (*p == CTLQUOTEMARK) 1237 p++; 1238 if (*p == CTLESC) 1239 p++; 1240 *enddir++ = *p++; --- 166 unchanged lines hidden (view full) --- 1407{ 1408 char name[20]; 1409 const char *nameend; 1410 wctype_t cclass; 1411 1412 *end = NULL; 1413 p++; 1414 nameend = strstr(p, ":]"); | 1233 if (start != name) { 1234 p = name; 1235 while (p < start) { 1236 while (*p == CTLQUOTEMARK) 1237 p++; 1238 if (*p == CTLESC) 1239 p++; 1240 *enddir++ = *p++; --- 166 unchanged lines hidden (view full) --- 1407{ 1408 char name[20]; 1409 const char *nameend; 1410 wctype_t cclass; 1411 1412 *end = NULL; 1413 p++; 1414 nameend = strstr(p, ":]"); |
1415 if (nameend == NULL || nameend - p >= sizeof(name) || nameend == p) | 1415 if (nameend == NULL || (size_t)(nameend - p) >= sizeof(name) || 1416 nameend == p) |
1416 return 0; 1417 memcpy(name, p, nameend - p); 1418 name[nameend - p] = '\0'; 1419 *end = nameend + 2; 1420 cclass = wctype(name); 1421 /* An unknown class matches nothing but is valid nevertheless. */ 1422 if (cclass == 0) 1423 return 0; --- 269 unchanged lines hidden --- | 1417 return 0; 1418 memcpy(name, p, nameend - p); 1419 name[nameend - p] = '\0'; 1420 *end = nameend + 2; 1421 cclass = wctype(name); 1422 /* An unknown class matches nothing but is valid nevertheless. */ 1423 if (cclass == 0) 1424 return 0; --- 269 unchanged lines hidden --- |