Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <4b595a5b-2164-4bf2-af8b-80992eb0a0fe@LBSD.net>
Date: Mon, 10 Jun 2024 05:38:36 +0000
From: Nigel Kukard <nkukard@...D.net>
To: "musl@...ts.openwall.com" <musl@...ts.openwall.com>
Subject: Different results with regex.h between Musl and Libc

Hi there,

I'm wondering if someone could possibly point out what I'm doing wrong here.

I tried searching the mailing list for similar topics, I found some 
relating to POSIX regex but none that really dealt with this issue with 
extended regex. I also didn't find anything really addressing this on 
https://wiki.musl-libc.org/functional-differences-from-glibc.html.

If I missed something I'm terribly sorry.


Musl output (Alpine 3.20), musl-1.2.5-r1...

The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
Match 0: 37
Match 1:
Match 2: 37

Glibc output (ArchLinux), glibc 2.39+r52+gf8e4623421-1...

The input '37' matches the pattern '^([0-9]*)?\.?([0-9]*)?$'
Match 0: 37
Match 1: 37
Match 2:


Test code...
/*--------------------*/
#include <stdio.h>
#include <regex.h>

int main() {
     const char *pattern = "^([0-9]*)?\\.?([0-9]*)?$";
     const char *input = "37";
     regex_t regex;
     regmatch_t matches[3];
     int ret;

     ret = regcomp(&regex, pattern, REG_EXTENDED);
     if (ret) {
         fprintf(stderr, "Could not compile regex\n");
         return 1;
     }

     ret = regexec(&regex, input, 3, matches, 0);
     if (!ret) {
         printf("The input '%s' matches the pattern '%s'\n", input, 
pattern);
         for (int i = 0; i < 3; i++) {
             if (matches[i].rm_so != -1) {
                 printf("Match %d: %.*s\n", i, matches[i].rm_eo - 
matches[i].rm_so, input + matches[i].rm_so);
             }
         }
     } else if (ret == REG_NOMATCH) {
         printf("The input '%s' does not match the pattern '%s'\n", 
input, pattern);
     } else {
         char msgbuf[100];
         regerror(ret, &regex, msgbuf, sizeof(msgbuf));
         fprintf(stderr, "Regex match failed: %s\n", msgbuf);
         return 1;
     }

     regfree(&regex);

     return 0;
}


Download attachment "OpenPGP_signature.asc" of type "application/pgp-signature" (237 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.