mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-12 04:15:06 -05:00
Add regex to delta code so we don't segfault when reading line
If the delta line doesn't match our regex, we won't go and process it, possibly walking off the end of the string. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
a50b067470
commit
b99bebc008
@ -618,7 +618,10 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
|
|||||||
_alpm_strtrim(line);
|
_alpm_strtrim(line);
|
||||||
if(strcmp(line, "%DELTAS%") == 0) {
|
if(strcmp(line, "%DELTAS%") == 0) {
|
||||||
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
|
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
|
||||||
info->deltas = alpm_list_add(info->deltas, _alpm_delta_parse(line));
|
pmdelta_t *delta = _alpm_delta_parse(line);
|
||||||
|
if(delta) {
|
||||||
|
info->deltas = alpm_list_add(info->deltas, delta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <regex.h>
|
||||||
|
|
||||||
/* libalpm */
|
/* libalpm */
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
@ -257,6 +259,19 @@ pmdelta_t *_alpm_delta_parse(char *line)
|
|||||||
{
|
{
|
||||||
pmdelta_t *delta;
|
pmdelta_t *delta;
|
||||||
char *tmp = line, *tmp2;
|
char *tmp = line, *tmp2;
|
||||||
|
regex_t reg;
|
||||||
|
|
||||||
|
regcomp(®,
|
||||||
|
"^[^[:space:]]* [[:xdigit:]]{32}"
|
||||||
|
" [^[:space:]]* [[:xdigit:]]{32}"
|
||||||
|
" [^[:space:]]* [[:xdigit:]]{32} [[:digit:]]*$",
|
||||||
|
REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
|
||||||
|
if(regexec(®, line, 0, 0, 0) != 0) {
|
||||||
|
/* delta line is invalid, return NULL */
|
||||||
|
regfree(®);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
regfree(®);
|
||||||
|
|
||||||
CALLOC(delta, 1, sizeof(pmdelta_t), RET_ERR(PM_ERR_MEMORY, NULL));
|
CALLOC(delta, 1, sizeof(pmdelta_t), RET_ERR(PM_ERR_MEMORY, NULL));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user