proc/sig.c: Harden print_given_signals().
And signal_name_to_number().
This commit is contained in:
parent
3244e7ddb0
commit
bf12b14db9
31
proc/sig.c
31
proc/sig.c
@ -177,7 +177,7 @@ int signal_name_to_number(const char *restrict name){
|
|||||||
val = strtol(name,&endp,10);
|
val = strtol(name,&endp,10);
|
||||||
if(*endp || endp==name) return -1; /* not valid */
|
if(*endp || endp==name) return -1; /* not valid */
|
||||||
}
|
}
|
||||||
if(val+SIGRTMIN>127) return -1; /* not valid */
|
if(val<0 || val+SIGRTMIN>127) return -1; /* not valid */
|
||||||
return val+offset;
|
return val+offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,33 +195,36 @@ const char *signal_number_to_name(int signo){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int print_given_signals(int argc, const char *restrict const *restrict argv, int max_line){
|
int print_given_signals(int argc, const char *restrict const *restrict argv, int max_line){
|
||||||
char buf[1280]; /* 128 signals, "RTMIN+xx" is largest */
|
char tmpbuf[16];
|
||||||
|
char buf[128 * sizeof tmpbuf]; /* 128 signals, "RTMIN+xx" is largest */
|
||||||
int ret = 0; /* to be used as exit code by caller */
|
int ret = 0; /* to be used as exit code by caller */
|
||||||
int place = 0; /* position on this line */
|
int place = 0; /* position on this line */
|
||||||
int amt;
|
if(argc < 0 || argc > 128) return 1;
|
||||||
if(argc > 128) return 1;
|
|
||||||
while(argc--){
|
while(argc--){
|
||||||
char tmpbuf[16];
|
int amt = -1;
|
||||||
const char *restrict const txt = *argv;
|
const char *restrict const txt = *argv;
|
||||||
if(*txt >= '0' && *txt <= '9'){
|
if(*txt >= '0' && *txt <= '9'){
|
||||||
long val;
|
long val;
|
||||||
char *endp;
|
char *endp;
|
||||||
val = strtol(txt,&endp,10);
|
val = strtol(txt,&endp,10);
|
||||||
if(*endp){
|
if(*endp || endp==txt){
|
||||||
fprintf(stderr, "Signal \"%s\" not known.\n", txt);
|
amt = -1;
|
||||||
ret = 1;
|
}else{
|
||||||
goto end;
|
amt = snprintf(tmpbuf, sizeof tmpbuf, "%s", signal_number_to_name(val));
|
||||||
}
|
}
|
||||||
amt = sprintf(tmpbuf, "%s", signal_number_to_name(val));
|
|
||||||
}else{
|
}else{
|
||||||
int sno;
|
int sno;
|
||||||
sno = signal_name_to_number(txt);
|
sno = signal_name_to_number(txt);
|
||||||
if(sno == -1){
|
if(sno == -1){
|
||||||
fprintf(stderr, "Signal \"%s\" not known.\n", txt);
|
amt = -1;
|
||||||
ret = 1;
|
}else{
|
||||||
goto end;
|
amt = snprintf(tmpbuf, sizeof tmpbuf, "%d", sno);
|
||||||
}
|
}
|
||||||
amt = sprintf(tmpbuf, "%d", sno);
|
}
|
||||||
|
if(amt <= 0 || (size_t)amt >= sizeof tmpbuf){
|
||||||
|
fprintf(stderr, "Signal \"%s\" not known.\n", txt);
|
||||||
|
ret = 1;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!place){
|
if(!place){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user