#269 new
Moinak Ghosh

Yasm segfaults on some GNU assembler files on OS X

Reported by Moinak Ghosh | May 9th, 2014 @ 06:09 PM

I was trying to use Yasm to build some GNU assembler files on OS X Mavericks and it kept segfaulting. After a some investigation I was able to get my code to build and work by making the following changes to gas-preproc.c:

index 96dec82..0ca18d0 100644
--- a/modules/preprocs/gas/gas-preproc.c
+++ b/modules/preprocs/gas/gas-preproc.c
@@ -409,12 +409,14 @@ static int gas_scan(void *preproc, struct tokenval *tokval)
             { "^^", TOKEN_DBL_XOR },
             { "||", TOKEN_DBL_OR }
         };
-        for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
-            if (!strcmp(str, ops[i].op)) {
-                tokval->t_type = ops[i].token;
-                break;
+       if (strlen(str) > 1) {
+            for (i = 0; i < sizeof(ops)/sizeof(ops[0]); i++) {
+                if (!strncmp(str, ops[i].op, 2)) {
+                    tokval->t_type = ops[i].token;
+                    break;
+                }
             }
-        }
+       }
     }

     if (tokval->t_type != TOKEN_INVALID) {
@@ -427,7 +429,7 @@ static int gas_scan(void *preproc, struct tokenval *tokval)
         tokval->t_type = c;

         /* Is it a symbol? If so we need to make it a TOKEN_ID. */
-        if (isalpha(c) || c == '_' || c == '.') {
+        if (isalpha(c) || c == '_' || c == '.' || c == '%') {
             int symbol_length = 1;

             c = get_char(pp);
@@ -829,7 +831,7 @@ static int eval_macro(yasm_preproc_gas *pp, int unused, char *args)
         skip_whitespace2(&line2);
         if (starts_with(line2, ".macro")) {
             nesting++;
-        } else if (starts_with(line, ".endm") && --nesting == 0) {
+        } else if (starts_with(line2, ".endm") && --nesting == 0) {
             return 1;
         }
         macro->num_lines++;

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Yasm Modular Assembler Project

Shared Ticket Bins

People watching this ticket

Pages